/*
    Content:     This file contains all KHV-specific code. Reusable functions should be abstracted to DR.Util().
    Styleguide: http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml
    Copyright:     2011 OverInteractive Media Inc. All rights reserved.
*/
KHV = new function(){
    // Data objects:
    this.data = {}; // for receiving data from back end
    this.arenas = {};
    
    this.galleryMenuTimeout = null;
    this.mousePosition = null;
    
    this.init = function() {
        // Called onDOMReady
        initPopovers();
        initEvents();
        initStars();
        //initEnableContent();
        initSocial('.i-social');
        
        $('a.i-disable').each(function(e) {
            var classes = this.className.replace(/i-\w+/gi, '');
            $(this).attr('class', classes + ' i-disable').unbind('click');
        }).css({'opacity':0.5, 'cursor': 'default'}).click( function(e) {
            e.preventDefault();
        });
        
        // Global buttons
        $('.i-header-switch-locale').click(function(){
            $('.i-header-admin').submit();
        });
        $('.i-logout-link').click(function(){
            $('.i-logout-form').submit();
        });
    }
    
    /* Individual pages */
    this.initIndex = function() {
        /* TODO: This was for the old carousel that allowed multi rows, but no auto scroll. 
        REMOVE this/commented out CSS when positive this carousel is not used.
        $('#idx-crsl-1').carousel({
            itemsPerPage: 5,
            itemsPerTransition: 5,
            //noOfRows: 1,
            pagination: false,
            nextPrevLinks: true,
            speed: 'normal',
            easing: 'swing'
        });*/
        
        /*$('.i-stats-qualified').click(function(){
            initArenaStateListPopups('qualified');
        });
        $('.i-stats-joined').click(function(){
            initArenaStateListPopups('joined');
        });*/
        
        $('#idx-crsl-1').jcarousel({
			scroll: 5
		});
        
        //Auto scrolling carousel for activity feed
        $('#i-act-feed').jcarousel({
			auto: 2,
			wrap: 'last',
			vertical: true,
			scroll: 1,
			initCallback: feedCarousel_initCallback
		});
    }
    
    function feedCarousel_initCallback(carousel) {
    	//Pauses carousel if user hovers over content
		carousel.clip.hover(function() {
			carousel.stopAuto();
		}, function() {
			carousel.startAuto();
		});
    }
    
    this.initProfile = function() {
        $('.i-inviteRecord').click(function(){
            DR.Social.invites('invite', true);
        });
        
        $('.i-twitter-connect').click(function() {
        	Id = window.Arcade.user.state.userId;
        	params = window.Arcade.user.signed_request;
        	newParams = params.substring(16);
        	
        	DR.log('userid ' + Id);
        	DR.log('signed Request ' + params);
        	
        	$.ajax({
			  url: '/apicust/sva/twitter-url?userId=' + Id + '&params=' + params,
			 dataType: 'json',
			 success: function(json) {
				DR.log("ajax response:", json);
				window.location = json.results;
			 },
				error: function(request, textStatus, error) {
				DR.log(error);
				}
			});           

        });
    }
    
    this.initChangePassword = function() {
        DR.log("Validating change password form");
        $("#i-change-password-form").validate({
            rules : {
                'cpw-password': {
                    required: true,
                    minlength: 6
                },
                'cpw-password-repeat': {
                    required: true,
                    equalTo: "#cpw-password"
                }
            }
        });
    }
    this.initContestRegistration = function() {
        
        // Hides gaurdian consent section until age is entered and below 19
        $('.i-reg-consent').hide();
        //Form validation
        $(".i-reg-form").validate({
            rules: {
                'reg-age': {
                    required: '#reg-age',
                    digits: true
                    //range:[19,120]
                },
                'reg-age-consent': {
                    required: true
                },
                'reg-opt-consent': {
                    required: true
                },
                'reg-rules': {
                	required: true
                }
            }
        });
        
        // Initiates after user unfocuses on the age field and will show gaurdian consent content based on age
        $('#reg-age').focusout(function() {
            var age = $('#reg-age').val();
            
            DR.log('age: ' + age);
            
            //Shows gaurdian consent content if user is under age(below 19)
            if(age < 19) {
                $('.i-reg-opt-ins').css('margin-top', '180px');
                $('.i-reg-consent').show();
                $('input[name=reg-age-consent]').attr('checked', false);
                $('input[name=reg-opt-consent]').attr('checked', false);
                
            } else {
                $('.i-reg-opt-ins').css('margin-top', '0px');
                $('.i-reg-consent').hide();
                $('input[name=reg-age-consent]').attr('checked', true);
                $('input[name=reg-opt-consent]').attr('checked', true);
            }
        });
    }
    
    this.initFindCommunity = function(){
        initArenaAutoComplete();
        initArenaListPopups();
        $("input[title]").inputHints();
        //initGoogleMap();
        
       $("#qualifiedcomms").tablesorter({sortList: [[0,0]]});
       
       $('.i-table-title').click(function() {
       		$('.i-table-title').removeClass('active');
       		$(this).addClass('active');
       });
       
       $('.i-cnd-navilink').click(function() {
       		$('.i-cnd-navilink').removeClass('active');
       		$(this).addClass('active');
       });
    }

    /* Arena autocomplete */
    function initArenaAutoComplete(){
        var arrayOfArenaStrings = [];
        for (var arena in KHV.arenaData) {
            arrayOfArenaStrings.push(KHV.arenaData[arena].name + ', ' + KHV.arenaData[arena].locn + ', ' + KHV.arenaData[arena].prov + ', ' + KHV.arenaData[arena].pst);
        }
        //DR.log(arrayOfArenaStrings.length);
        $('.i-arena-suggest').autocomplete({ 
            source: arrayOfArenaStrings,
            appendTo: "#search-controls",
            position: { my : "left top", at: "left bottom", of: "#search-controls form", offset: "8 -9" },
            minLength: 3,
            width: 560,
            search: function(event, ui) {  },
            create: function(event, ui) { $(".ui-autocomplete").removeClass('ui-corner-all').addClass('khv-autocomplete'); },
            open: function(event, ui)    {
                $(".ui-menu-item:nth-child(n+6)").addClass('expanded-list');
                $(".ui-autocomplete").append('<li class="ui-menu-footer show-more"><a href="#">See All Search Results</a></li>');
                $(".show-more").live("click", function(e) {
                    e.preventDefault();
                    $('.ui-menu-footer.show-more').remove();
                    $('.ui-menu-item.expanded-list').removeClass(".expanded-list").show();
                });
            },
            close: function(event, ui) {
                
                //Loop through KHV.arenaData
                for (var arena in KHV.arenaData) {
                    if($('.i-arena-suggest').val().indexOf(KHV.arenaData[arena].name + ', ' + KHV.arenaData[arena].locn) != -1){
                        document.location.href = '/community/index/cid/' + arena + window.Arcade.params;
                    }
                }
            }
        });
    }

    /* Arena list popups */
    function initArenaListPopups(){
        $('.i-arena-list a').click(function(){
            // Get data from page
            var province = $('.i-data-province', $(this)).val();
            
            // Get array of arenas for this province
            var provArenas = [];
            for (var arena in KHV.arenaData) {
                if(KHV.arenaData[arena].prov == province){
                    KHV.arenaData[arena].id = arena
                    provArenas.push(KHV.arenaData[arena]);
                }
            }

            provArenas.sort(compare);
            
            // Put them into the popup
            var html1 = '';
            var html2 = '';
            var counter = 0;
            DR.log(provArenas.length + ' arenas found');
            //DR.log('Arena Names: ' + provArenas);
            //DR.log('Arena: ' + arena);
            for (var arena in provArenas) {
                if(counter < Math.floor(provArenas.length / 2)){
                    html1 += '<li><a href="/community/index/cid/' + provArenas[arena].id + window.Arcade.params + '">' + provArenas[arena].name + '</a>, ' + provArenas[arena].locn + '</li>';
                } else {
                    html2 += '<li><a href="/community/index/cid/' + provArenas[arena].id + window.Arcade.params + '">' + provArenas[arena].name + '</a>, ' + provArenas[arena].locn + '</li>';
                }
                counter++;
            }
            $('.i-pop-arenas .i-column1').html(html1);
            $('.i-pop-arenas .i-column2').html(html2);
            
            // Set title
            $('.i-pop-arenas-title').text($(this).text());
            
            $('.i-pop-arenas').show();
            positionPopup('.i-pop-arenas .i-pop-inner')
        });
    }
    
    // Sorts the arena list alphabetically
    function compare(a,b) {
      if (a.name < b.name)
         return -1;
      if (a.name > b.name)
        return 1;
      return 0;
    }

    
    
    this.faq_labels = {
        en : {
            show : "Show the full answer",
            hide : "Hide the full answer"
        },
        fr : {
            show : "Afficher la r&eacute;ponse compl&egrave;te",
            hide : "Cacher la r&eacute;ponse compl&egrave;te"
        }
    };
    
    this.initFAQ = function() {
    	//Hide all FAQ videos/hide video text on page load
        $('.i-faq-vplayer').hide();
        $('.i-faq-hide-video').hide();
        
        // Display topic selected from URL
        var def_topic = $('.i-default-topic').val();
        displayFaqTopic('faq_topic_' + def_topic);
        minimizeFaqAnswer();

        $('.i-faq-heading').click(function(e) {
            e.preventDefault();
            var topic = $(this).attr('rel');
            displayFaqTopic(topic);
            minimizeFaqAnswer();
            
            //Hide the video and stop it from playing when user changes topics
            $('.i-faq-vplayer').hide();
            $('.i-faq-vplayer').attr('src', '');
            //Hides video link and shows watch video link when user switches topics
            $('.i-faq-hide-video').hide();
            $('.i-faq-video-link').show();
        });

        $('.i-faq-show-full').live('click', function(e) {
            e.preventDefault();
            
            var labels = KHV.faq_labels[window.Arcade.user.state.language];
            
            if ( $(this).hasClass('faq-state-show')) {
                $(this).removeClass('faq-state-show').addClass('faq-state-hide').html(labels['hide'] + ' &laquo;');
                $(this).parent().prev().removeClass("preview_text").addClass('full_text');
            } else {
                $(this).removeClass('faq-state-hide').addClass('faq-state-show').html(labels['show'] + ' &raquo;');
                $(this).parent().prev().removeClass("full_text").addClass('preview_text');
            }
        });
        
        //Play FAQ Video
        $('.i-faq-video-link').click(function() {
        	var vid = $('.i-faq-videoId', this).val();
        	var topic = $('.i-faq-video-topic', this).val();
        	
        	DR.log('Vid Id: ' + vid + ' and topic is: ' + topic);
        	
        	$('.i-faq-video-' + topic + ' iframe').attr('src', '//www.youtube.com/embed/' + vid + '?rel=0&autoplay=1&wmode=transparent');
        	$('.i-faq-video-' + topic + ' iframe').show();
        	$(this).hide();
        	$('.i-faq-hide-video').show();
        });
        
        $('.i-faq-hide-video').click(function() {
        	$('.i-faq-vplayer').hide();
            $('.i-faq-vplayer').attr('src', '');
        	$(this).hide();
        	$('.i-faq-video-link').show();
        });
    } // initFAQ
    
    
    this.initMissionStarters = function() {
    	$('.i-ms-toggle-section.hide').css("display", "none");
    	$('.ms-toggle-section').css("display", "none");
    	
    	$('.i-ms-toggle-section').click(function () {
    		var msSectionArray = $(this).attr("id").split("_");
    		var msSectionID = msSectionArray[1];
    		var msSection = $('#ms-toggle-section_' + msSectionID);
    		var msSectionShow = $('#i-ms-toggle-section-show_' + msSectionID);	
    		var msSectionHide = $('#i-ms-toggle-section-hide_' + msSectionID);			
    		
    		if (msSection.is(":hidden")) {
    			msSection.slideDown(200);
    			msSectionHide.css("display", "block");
    			msSectionShow.css("display", "none");
    		} else {
    			msSection.slideUp(200);
    			msSectionHide.css("display", "none");
    			msSectionShow.css("display", "block");    			
    		}
    	});
    } //initMissionStarters
    
    function displayFaqTopic(topic) {
        if ($("#" + topic).is(":hidden")) {
            $('.faq_topic').each( function() {
                if ($(this).attr('id') == topic) {
                    $(this).css({'display':'block'});
                } else {
                    $(this).css({'display':'none'});
                }
            });
            $("li.selected").removeClass('selected');
            $('li[rel="' + topic + '"]').addClass('selected');
        }
    } // displayFaqTopic
    
    function minimizeFaqAnswer() {
        var two_line_height = 40;
        // Must be the same height as: #faq .faq_topic .preview_text

        var labels = KHV.faq_labels[window.Arcade.user.state.language];

        // Truncate longer answers
        $('.i-faq-q-toggle').each( function(e) {
            if ($(this).next("li").height() > two_line_height && !($(this).next("li").hasClass("preview_text") || $(this).next("li").hasClass("full_text")) ) {
                $(this).next("li").addClass("preview_text");
                $(this).parent().append($("<li></li>").html('<p class="i-faq-show-full text-as-link faq-state-show">' + labels['show'] + ' &raquo;</a>'));
            }
        });
    }
    
    /* Get hash tag for requested community */
    this.ArenaHash = function(vin){
        var outhash = KHV.arenaData[vin].pst.substring(0,3);
        //$("i-data-pst-hash").val(outhash);
        //$("i-data-pst-hash-txt").html(outhash);
        return outhash;
    }
    
    /* Google map */
    this.gmap = {};
    this.gmap.markersArray = [];
    this.gmap.markerClusterer;
    this.gmap.markersAdded = false;
    function initGoogleMap(){

        var STARTZOOM = 4, // Marker holder (to allow for removal of all markers
            latlng = new google.maps.LatLng(56.4, 268),
            mapConfig = {
                zoom: STARTZOOM,
                center: latlng,
                //zoomControl: true,
                streetViewControl: false,
                mapTypeControl: false,
                minZoom: STARTZOOM,
                mapTypeId: google.maps.MapTypeId.TERRAIN//ROADMAP
            },
            map = new google.maps.Map(document.getElementById('googleMap'), mapConfig);
        
        google.maps.event.addListener(map, 'zoom_changed', function() {
            if (map.getZoom() >= (STARTZOOM + 1) && KHV.gmap.markersAdded == false){
                addMarkers(map, KHV.arenaData);
                KHV.gmap.markersAdded = true;
            } else if (map.getZoom() <= STARTZOOM){
                removeMarkers(map);
                KHV.gmap.markersAdded = false;
            };
        });
    }
    
    function removeMarkers(map){
        // Remove all markers
        if (KHV.gmap.markersArray) {
            for (i in KHV.gmap.markersArray) {
                KHV.gmap.markerClusterer.clearMarkers();
                KHV.gmap.markersArray = [];
            }
        }
    }
    
    function addMarkers(map, arenas){
        for(var key in arenas){
            var rink = arenas[key];
            var marker = new google.maps.Marker({
                // These attributes generally have setters. E.g.: marker.setMap(map);
                position: new google.maps.LatLng(rink.y, rink.x),
                title:rink.name,
                icon: '/' + KHV.data.assetVersion + '/img/gmap/marker.png'
                //map: map
            });
          
            // Multiple infowindow code
            var infowindow = new google.maps.InfoWindow({});
            // Note need to pass in data for info window content to be correctly scoped
            google.maps.event.addListener(marker, 'click', (function(marker, name, locn, prov, key) {
                return function() {
                    infowindow.setContent('<p><strong>' + name + '</strong></p><p>' + locn + ', ' + prov + '</p><p><a href="/community/index/cid/' + key + window.Arcade.params + '">Goto to this community</a></p>');
                    infowindow.open(map,marker);
                }
            })(marker, rink.name, rink.locn, rink.prov, key));

            KHV.gmap.markersArray.push(marker);
            
        }
        // Cluster markers
        //Cluster styles example
        //view-source:http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/examples/advanced_example.html
        var mcOptions = {gridSize: 50, maxZoom: 7};
        KHV.gmap.markerClusterer = new MarkerClusterer(map, KHV.gmap.markersArray, mcOptions);
    }
    
    this.provinces = {
        en : {
            AB : "Alberta",
            BC : "British Columbia",
            MB : "Manitoba",
            NB : "New Brunswick",
            NL : "Newfoundland & Labrador",
            NT : "Northwest Territories & Nunavut",
            NS : "Nova Scotia",
            ON : "Ontario",
            PE : "Prince Edward Island",
            QC : "Quebec",
            SK : "Saskatchewan",
            YT : "Yukon Territory"
        },
        fr : {
            AB : "Alberta",
            BC : "Colombie-Britannique",
            PE : "Île-du-Prince-Édouard",
            MB : "Manitoba",
            NB : "Nouveau-Brunswick",
            NS : "Nouvelle-Écosse",
            ON : "Ontario",
            QC : "Québec",
            SK : "Saskatchewan",
            NL : "Terre-Neuve & Labrador",
            NT : "Territoires du Nord-Ouest & Nunavut",
            YT : "Yukon"
        }
    };
        
    function initArenaStateListPopups(popupType){
        popupType = popupType ? popupType : "joined";
        
        var provinces = KHV.provinces[window.Arcade.user.state.language],
            html = '<div class="column1">',
            counterAll = 0,
            secondColumnStarted = false;
        
        // Show correct header + text
        $('.i-pop-joined-arenas .i-joined, .i-pop-joined-arenas .i-qualified').hide();
        $('.i-pop-joined-arenas .i-' + popupType).show();
        
        // For each province...
        for (var province in provinces) {
            // Start a second column if past half way
            if(counterAll > (KHV.arenas[popupType].length / 2) && !secondColumnStarted){
                html += '</div><div class="column2">';
                secondColumnStarted  = true;
            }
            html += "<h3>" + provinces[province] + "</h3><ol>";
            var counterProvince = 0;
            
            //Sorting names alphabetically for Chrome Browsers
            //DR.log('community names: ' + KHV.arenaData[KHV.arenas[popupType]].name);
            //KHV.arenaData[KHV.arenas[popupType].name.sort();
            //DR.log('Sorted');
            
            // ...compile a list of active arenas
            for (var i = 0; i < KHV.arenas[popupType].length; i++){
                if (province == KHV.arenaData[KHV.arenas[popupType][i]].prov){
                    //DR.log(KHV.arenaData[KHV.arenas[popupType][i]].name + ", " + KHV.arenaData[KHV.arenas[popupType][i]].prov);
                    html += '<li><a href="/community/index/cid/' + KHV.arenas[popupType][i]+ window.Arcade.params + '">' + KHV.arenaData[KHV.arenas[popupType][i]].name + '</a>, ' + KHV.arenaData[KHV.arenas[popupType][i]].locn + '</li>'
                    counterProvince++;
                    counterAll++;
                }
            }
            if (counterProvince == 0){
                html += '<li>' + $('.i-pop-joined-arenas .i-data-no-communities').val() + '</li>';
            }
            html += "</ol>";
        }
        html += "</div>";
        
        $('.i-pop-joined-arenas .i-lists').html(html);
        $('.i-pop-joined-arenas').show();
        positionPopup('.i-pop-joined-arenas .i-pop-inner');
    }
    
    function initStars() {
        $('.i-star').click(function(event){
            var contentId = $('.i-data-itemid', $(this)).val();
            DR.log("Star for ID " + contentId + " clicked");
            var currentStars = parseInt($('.i-pop-media .i-pop-inner:visible .i-pop-stars-num').text());

            DR.log("Number of stars from hidden input on page before: " + $('.i-data-id[value=' + contentId + ']').siblings('.i-data-stars').val())
            if($(this).attr('class').indexOf('highlight') == -1){
                // Not already clicked
                $(this).addClass('highlight');
                // If in popup, increment displayed value
                $('.i-pop-media .i-pop-inner:visible .i-pop-stars-num').text(currentStars + 1);
                // Update hidden page values
                $('.i-data-id[value=' + contentId + ']').siblings('.i-data-stars').val( parseInt($('.i-data-id[value=' + contentId + ']').siblings('.i-data-stars').val()) + 1 );
                //$('.i-data-id[value=' + contentId + ']').siblings('.i-data-stars').val( parseInt($('.i-data-id[value=' + contentId + ']').siblings('.i-data-stars').val()) + 1 );
                $('.i-data-id[value=' + contentId + ']').siblings('.i-data-starred').val(1);
                // Add highlight to page element in the case of starring within the popup 
                $('.i-data-id[value=' + contentId + ']').siblings('.i-star').addClass('highlight');
            } else {
                // Already clicked
                $(this).removeClass('highlight');
                $('.i-pop-media .i-pop-inner:visible .i-pop-stars-num').text(currentStars - 1);
                $('.i-data-id[value=' + contentId + ']').siblings('.i-data-stars').val( parseInt($('.i-data-id[value=' + contentId + ']').siblings('.i-data-stars').val()) - 1 );
                $('.i-data-id[value=' + contentId + ']').siblings('.i-data-starred').val(0);
                $('.i-data-id[value=' + contentId + ']').siblings('.i-star').removeClass('highlight');
            }
            DR.log("Number of stars from hidden input on page after: " + $('.i-data-id[value=' + contentId + ']').siblings('.i-data-stars').val())
            //DR.log('Send contentId (' + contentId + ') to async starring service');
            DR.Sva.star(contentId);
            
            // Prevent click bubbling up to surrounding elements
            event.stopPropagation();
        });
    }
    
    /*
    function initEnableContent() {
        $('.i-enable-content').click(function(event) {
            var contentID = $(this).attr('id');
            if ($(this).hasClass('enabled')) {
                $(this).addClass('disabled').removeClass('enabled');
                $(this).html("DISABLED"); 
                DR.Sva.enableToggleContent(contentID,1);
            } else {
                $(this).addClass('enabled').removeClass('disabled');
                $(this).html("ENABLED");
                DR.Sva.enableToggleContent(contentID,0);
            }
            // Prevent click bubbling up to surrounding elements
            event.stopPropagation();
        });
    }
    */
    
    function initEvents(){
        /** Events **/

        // Facebook user joins app
        if (window.Arcade.events.website_join && window.Arcade.user.state.type == 'facebook' ) {
            helpPopover('newFBUser',{
                btn1Function : function() {
                    DR.Social.feed('joinedApp');
                },
                btn2Function : function() {
                	//Make sure the user isn't already part of a community before prompting them to join one
                	if (!window.Arcade.user.state.community) {
						helpPopover('notJoinedCommunity', {
							btn1Function : function() {
								document.location.href = '/index/find-community/' + window.Arcade.params;
							}
						});
                    } else {
                    	$('.i-pop').hide();
                    }
                }
            });
        }
        // Email user joins app
        if (window.Arcade.events.website_join && window.Arcade.user.state.type == 'email' ) {
            helpPopover('newEmailUser',{
                btn1Function : function() {
                    document.location.href = '/index/find-community/' + window.Arcade.params;
                }
            });
        }
        
        // Sign in
        // Not joined a community
        if (window.Arcade.events.signin && !window.Arcade.user.state.community ) {
            helpPopover('notJoinedCommunity');
        }
        
        // Uploads
        if (window.Arcade.events.upload_photo || window.Arcade.events.upload_note || window.Arcade.events.upload_video) {
            if (window.Arcade.events.upload_note == 1){
                // Mission 1, note
                if(window.Arcade.user.state.type == 'facebook'){
                    // FB
                    helpPopover('upload1NoteFB', {
                        btn1Function : function() {
                            DR.Social.feed('uploadNoteM1');
                        },
                        btn2Function : function() {
                            $('.i-pop').hide();
                        }
                    });
                } else {
                    // Email
                    helpPopover('upload1NoteEmail');
                }
            } else if (window.Arcade.events.upload_photo == 1){
                // Mission 1, photo
                if(window.Arcade.user.state.type == 'facebook'){
                    // FB
                    DR.log('mission 1 photo');
                    helpPopover('upload1PhotoFB', {
                        btn1Function : function() {
                            DR.Social.feed('uploadPhotoM1');
                        },
                        btn2Function : function() {
                            $('.i-pop').hide();
                        }
                    });
                } else {
                    // Email
                    helpPopover('upload1PhotoEmail');
                }
            } else if (window.Arcade.events.upload_video == 3){
                    // Mission 3, video
                    if(window.Arcade.user.state.type == 'facebook'){
                        // FB
                        DR.log('Mission 3 Complete Video FB');
                        helpPopover('msn3CompleteFB', {
                            btn1Function : function() {
                                DR.Social.feed('msn3');
                            },
                            btn2Function : function() {
                                $('.i-pop').hide();
                            }
                        });
                    } else {
                        // Email
                        DR.log('Mission 3 Complete Video Email');
                        helpPopover('msn3CompleteEmail');
                    }
                } else if (window.Arcade.events.upload_photo == 3){
                    // Mission 3, photo
                    if(window.Arcade.user.state.type == 'facebook'){
                        // FB
                        DR.log('Mission 3 Complete Photo FB');
                        helpPopover('msn3CompleteFB', {
                            btn1Function : function() {
                                DR.Social.feed('msn3');
                            },
                            btn2Function : function() {
                                $('.i-pop').hide();
                            }
                        });
                    } else {
                        // Email
                        DR.log('Mission 3 Complete Photo Email');
                        helpPopover('msn3CompleteEmail');
                    }
            } else if (window.Arcade.events.upload_video == 4){
                // Mission 4, video
                if(window.Arcade.user.state.type == 'facebook'){
                    // FB
                    helpPopover('msn4CompleteFB', {
                        btn1Function : function() {
                            DR.Social.feed('msn4');
                        },
                        btn2Function : function() {
                            $('.i-pop').hide();
                        }
                    });
                } else {
                    // Email
                    helpPopover('msn4CompleteEmail');
                }
            } else if (window.Arcade.events.upload_photo == 4){
                // Mission 4, photo
                if(window.Arcade.user.state.type == 'facebook'){
                    // FB
                    helpPopover('msn4CompleteFB', {
                        btn1Function : function() {
                            DR.Social.feed('msn4');
                        },
                        btn2Function : function() {
                            $('.i-pop').hide();
                        }
                    });
                } else {
                    // Email
                    helpPopover('msn4CompleteEmail');
                }
            } else if (window.Arcade.events.upload_note == 4){
                // Mission 4, note
                if(window.Arcade.user.state.type == 'facebook'){
                    // FB
                    helpPopover('msn4CompleteFB', {
                        btn1Function : function() {
                            DR.Social.feed('msn4');
                        },
                        btn2Function : function() {
                            $('.i-pop').hide();
                        }
                    });
                } else {
                    // Email
                    helpPopover('msn4CompleteEmail');
                }
            } else if (window.Arcade.events.upload_video == 5){
                // Mission 5, video
                if(window.Arcade.user.state.type == 'facebook'){
                    // FB
                    helpPopover('msn5CompleteFB', {
                        btn1Function : function() {
                            DR.Social.feed('msn5');
                        },
                        btn2Function : function() {
                            $('.i-pop').hide();
                        }
                    });
                } else {
                    // Email
                    helpPopover('msn5CompleteEmail');
                }
            } else if (window.Arcade.events.upload_photo == 5){
                // Mission 5, photo
                if(window.Arcade.user.state.type == 'facebook'){
                    // FB
                    helpPopover('msn5CompleteFB', {
                        btn1Function : function() {
                            DR.Social.feed('msn5');
                        },
                        btn2Function : function() {
                            $('.i-pop').hide();
                        }
                    });
                } else {
                    // Email
                    helpPopover('msn5CompleteEmail');
                }
            } else if (window.Arcade.events.upload_note == 5){
                // Mission 5, note
                if(window.Arcade.user.state.type == 'facebook'){
                    // FB
                    helpPopover('msn5CompleteFB', {
                        btn1Function : function() {
                            DR.Social.feed('msn5');
                        },
                        btn2Function : function() {
                            $('.i-pop').hide();
                        }
                    });
                } else {
                    // Email
                    helpPopover('msn5CompleteEmail');
                }
            } else {
                // Failsafe
                DR.log('Failsafe');
                helpPopover('upload');
            }
        } 
        
        //Entered early bird
        /*if (window.Arcade.events.early_bird) {
            if(window.Arcade.user.state.type == 'facebook') {
                helpPopover('earlyBirdFBConfirm', {
                    btn1Function : function() {
                        DR.Social.feed('enteredEarlyBird');
                    },
                    btn2Function : function() {
                        document.location.href = '/community/index/cid/' + window.Arcade.user.state.community + window.Arcade.params;
                    }
                });
            } else {
                helpPopover('earlyBirdEmailConfirm', {
                    btn1Function : function() {
                        document.location.href = '/community/index/cid/' + window.Arcade.user.state.community + window.Arcade.params;
                    }
                });
            }
        }*/
        
        // Reminder to enter early bird (user is qualified and is on their own community page)
        /*if (window.Arcade.events.earlyBirdReminder) {
            if(!$.cookie("khv_earlyBirdReminder")){
                helpPopover('earlyBirdReminder', {
                    btn1Function : function() {
                        document.location.href = '/index/early-bird' + window.Arcade.params;
                    }
                });
                $.cookie("khv_earlyBirdReminder", "1");
            }
        }*/

        // Joined a community
        if (window.Arcade.events.group_join) {
            if(window.Arcade.user.state.type == 'facebook') {
                helpPopover('joinedGroupFB', {
                    btn1Function : function() {
                        DR.Social.feed('joinedCommunity', window.Arcade.events.group_join);
                        $('.i-pop').hide();
                    },
                    btn2Function : function() {
                        $('.i-pop').hide();
                    }
                });
            } else {
                helpPopover('joinedGroupEmail', {
                    btn1Function : function() {
                        $('.i-pop').hide();
                    }
                });
            }
        }

        // Submitted a missing community
        if (window.Arcade.events.group_request) {
            helpPopover('requestGroup', {
                btn1Function : function() {
                    document.location.href = '/' + window.Arcade.params;
                }
            });
        }
        
        // Submitted a removal of content request
        if (window.Arcade.events.content_removal_request) {
            helpPopover('requestGroup', {
                btn1Function : function() {
                    $('.i-pop').hide();
                }
            });
        }

        /** User clicks **/
        // Not logged in
        if(!window.Arcade.user.state.loggedIn){
            // All users to see sign in popup for first fortnight
            /*if(!$.cookie("khv_unsignedsession")){
                helpPopover('signIn',{
                    btn1Function : function(){
                        DR.Facebook.login();
                        DR.log('Facebook login');
                        $('.i-pop-help').hide();
                    },
                    btn2Function : function(){
                        $('.i-pop-help').hide();
                        $('.i-pop-signin').show();
                        positionPopup('.i-pop-signin .i-pop-inner');
                    },
                    btn3Function : function(){
                        $('.i-pop-help').hide();
                        $('.i-pop-reg').show();
                        positionPopup('.i-pop-reg .i-pop-inner');
                    }
                });
                $.cookie("khv_unsignedsession", "1", {path : '/'});
            }*/
                
            //clicks something requiring login
            $('.i-all-missions, .i-join-us, .i-search-methods, .i-tweet, .i-early-enter').click(function(){
                helpPopover('signIn',{
                    btn1Function : function(){
                        DR.Facebook.login();
                        DR.log('Facebook login');
                        $('.i-pop-help').hide();
                    },
                    btn2Function : function(){
                        $('.i-pop-help').hide();
                        $('.i-pop-signin').show();
                        positionPopup('.i-pop-signin .i-pop-inner');
                    },
                    btn3Function : function(){
                        $('.i-pop-help').hide();
                        $('.i-pop-reg').show();
                        positionPopup('.i-pop-reg .i-pop-inner');
                    }
                });
                return false;
            });
        } else {
            // Logged in
            // Joins community
            $('.i-join-us').click(function(){
            	if(!$.cookie("khv_joinThisCommunity")) {
					helpPopover('joinCommunity',{
						btn1Function : function(){
							 document.location.href = '/index/contest-registration/' + window.Arcade.params + '&community=' + KHV.data.currentCid;
						},
						btn2Function : function(){
							$('.i-pop-help').hide();
						}
					});
                } else {
                	document.location.href = '/index/contest-registration/' + window.Arcade.params + '&community=' + KHV.data.currentCid;
                }
            });
            // Wants to submit a missing community
            $('.i-search-methods').click(function(){
                helpPopover('cantFindCommunity',{
                    btn1Function : function(){
                        document.location.href = '#fnd-prov-list' + window.Arcade.params;
                        $('.i-pop-help').hide();
                    },
                    btn2Function : function(){
                        $('.i-pop-submitcmt').show();
                        positionPopup('.i-pop-submitcmt .i-pop-inner');
                        $('.i-pop-help').hide();
                    }
                });
            });
            /*if(!window.Arcade.user.state.community){
                // Not a community member
                $('.i-all-missions, .i-early-enter').click(function(){
                    helpPopover('notJoinedCommunity', {
                        btn1Function : function(){
                            document.location.href = '/index/find-community/' + window.Arcade.params;
                        }
                    });
                    return false;
                });
            } else {
                // Signed in community member
                if(window.Arcade.user.state.communityQualified){
                    if(window.Arcade.user.state.enteredEarly){
                        // Already entered
                        $('.i-early-enter').unbind().click(function() {
                            helpPopover('enteredEarly');
                        });
                    } else {
                        // Enter Early Bird
                        $('.i-early-enter').unbind().click(function() {
                            $('.i-pop-early').show();
                            positionPopup('.i-pop-early .i-pop-inner');
                            return false
                        });
                    }
                } else {
                    $('.i-early-enter').unbind().click(function() {
                        // Go and qualify before entering Early Bird
                        helpPopover('unqualifiedCommunity', {
                            btn1Function : function(){
                                document.location.href = '/community/missions/cid/' + window.Arcade.user.state.community + window.Arcade.params;
                            }
                        });
                    });
                }
            }*/
        }
        
        /** Sign up registration forms **/
        //user does not exist
        if (window.Arcade.events.login_username_error) { 
            helpPopover('usernameError');
        }
        //incorrect password
        if (window.Arcade.events.login_password_error) { 
            helpPopover('passwordError');
        }
        //email username already taken
        if (window.Arcade.events.registration_error) { 
            helpPopover('registerError');
        }
        // Facebook user logging in via email
        if (window.Arcade.events.login_use_facebook) {
            helpPopover('useFacebook');
        }
        // Email sent to user who's forgotten password
        if (window.Arcade.events.password_email_sent) {
            helpPopover('forgotPwdEmailed');
        }
        // Email sent to user who's forgotten password
        if (window.Arcade.events.password_changed) {
            helpPopover('forgotPwdChanged');
        }

        /** Error **/
        if (window.Arcade.events.internal_error) {
            helpPopover('internalError');
        }
        
        // User completes mission 2
        if(window.Arcade.events.mission2_complete && window.Arcade.user.state.type == 'facebook') {
            helpPopover('msn2CompleteFB', {
                btn1Function : function(){
                    DR.Social.feed('msn2');
                    $('.i-pop').hide();
                },
                btn2Function : function(){
                    $('.i-pop-help').hide();
                }
            });
        }
        
        if(window.Arcade.events.mission2_complete && window.Arcade.user.state.type == 'email') {
            helpPopover('msn2CompleteEmail', {
                btn1Function : function(){
                    $('.i-pop-help').hide();
                }
            });
        }
        
        //Banner Achievements
        if(window.Arcade.events.banner1 && window.Arcade.user.state.type == 'facebook') {
            helpPopover('popupBanner1FB', {
                btn1Function : function(){
                    DR.Social.feed('banner1');
                    $('.i-pop-help').hide();
                },
                btn2Function : function(){
                    $('.i-pop-help').hide();
                }
            });
        }
        
        if(window.Arcade.events.banner2 && window.Arcade.user.state.type == 'facebook') {
            helpPopover('popupBanner2FB', {
                btn1Function : function(){
                    DR.Social.feed('banner2');
                    $('.i-pop-help').hide();
                },
                btn2Function : function(){
                    $('.i-pop-help').hide();
                }
            });
        }
        
        if(window.Arcade.events.banner3 && window.Arcade.user.state.type == 'facebook') {
            helpPopover('popupBanner3FB', {
                btn1Function : function(){
                    DR.Social.feed('banner3');
                    $('.i-pop-help').hide();
                },
                btn2Function : function(){
                    $('.i-pop-help').hide();
                }
            });
        }
        
        if(window.Arcade.events.banner4 && window.Arcade.user.state.type == 'facebook') {
            helpPopover('popupBanner4FB', {
                btn1Function : function(){
                    DR.Social.feed('banner4');
                    $('.i-pop-help').hide();
                },
                btn2Function : function(){
                    $('.i-pop-help').hide();
                }
            });
        }
        
        if(window.Arcade.events.banner5 && window.Arcade.user.state.type == 'facebook') {
            helpPopover('popupBanner5FB', {
                btn1Function : function(){
                    DR.Social.feed('banner5');
                    $('.i-pop-help').hide();
                },
                btn2Function : function(){
                    $('.i-pop-help').hide();
                }
            });
        }
        
        if(window.Arcade.events.banner6 && window.Arcade.user.state.type == 'facebook') {
            helpPopover('popupBanner6FB', {
                btn1Function : function(){
                    DR.Social.feed('banner6');
                    $('.i-pop-help').hide();
                },
                btn2Function : function(){
                    $('.i-pop-help').hide();
                }
            });
        }
        
        //Show join community popup if user is not part of a community and is on a community page
        //Also sets a cookie, so the user will only see this popup once per session
        if (window.Arcade.user.state.community == false && KHV.data.currentCid != 0 && window.Arcade.user.state.loggedIn == true) {
        	DR.log('User has not joined a community and is on a community page');
            if(!$.cookie("khv_joinThisCommunity")){
            	DR.log('Show join community popup');
                helpPopover('joinCommunity',{
                    btn1Function : function(){
                         document.location.href = '/index/contest-registration/' + window.Arcade.params + '&community=' + KHV.data.currentCid;
                    },
                    btn2Function : function(){
                        $('.i-pop-help').hide();
                    }
                });
                $.cookie("khv_joinThisCommunity", "1");
            }
        }
    }
    
    this.initCommunityHeader = function() {
        menuTimeoutValue = 200;
        
        $('.i-dropdown').mouseenter(function(){
            KHV.mousePosition = "i-dropdown";
            if (KHV.galleryMenuTimeout != null) {
                clearTimeout(KHV.galleryMenuTimeout);
                KHV.galleryMenuTimeout = null;
            }
            $('.galleryDropDownMenu').slideDown();
        }).mouseout(function(){
            KHV.mousePosition = null;
            KHV.galleryMenuTimeout = window.setTimeout(function(){
                if (KHV.mousePosition == null) {
                    $('.galleryDropDownMenu').slideUp();
                }
            }, menuTimeoutValue);            
        });
        
        $('.galleryDropDownMenu a').mouseenter(function(){
            KHV.mousePosition = 'galleryDropDownMenu';
            if (KHV.galleryMenuTimeout != null) {
                clearTimeout(KHV.galleryMenuTimeout);
                KHV.galleryMenuTimeout = null;
            }
        }).mouseout(function(){
            KHV.mousePosition = null;
            KHV.galleryMenuTimeout = window.setTimeout(function(){
                if (KHV.mousePosition == null) {
                    $('.galleryDropDownMenu').slideUp();
                }
            }, menuTimeoutValue);
        });
        
        $('.i-qualifiedShare').click(function() {
        	type = $('.i-data-fbShare', this).val();
        	arena = $('.i-data-communityName', this).val();
        	returnLink = $('.i-data-returnLink', this).val();
        	DR.log('data: ' + type + ' , ' + arena + ' , ' + returnLink);
        	DR.Social.feed(type, arena, returnLink);
        });
    }
    
    this.initAlbum = function() {
        DR.log('Your are on the album page!');
        
        /* NOTE: Pagination Plugin for albums
        var rows = 1;
        var items = $('.i-item').length;
        DR.log('Number of items: ' + items);
        
        if(items > 6) {
            rows = 3;
        } else if(items > 3) {
            rows = 2;
        }
        
        DR.log('Rows: ' + rows);
        
        $('#cmt-crsl').carousel({
            itemsPerPage: 9,
            itemsPerTransition: 3,
            noOfRows: rows,
            pagination: true,
            nextPrevLinks: true,
            speed: 'normal',
            easing: 'swing'
        });*/
        
        var id = $('.i-data-shared-id').val();
        var image = $('.i-data-shared-image').val();
        var title = $('.i-data-shared-title').val();
        var story = $('.i-data-shared-story').val();
        var cid = $('.i-data-shared-cid').val();
        var aid = $('.i-data-shared-aid').val();
        var gid = $('.i-data-shared-gid').val();
        var creator = $('.i-data-shared-by').val();
        var stars = $('.i-data-shared-stars').val();
        var starred = $('.i-data-shared-starred').val();
        var imgheight = $('.i-data-shared-height').val();
        var imgwidth = $('.i-data-shared-width').val();
        var type = $('.i-data-shared-type').val();
        var vid = $('.i-data-videoid', element).val();
        
        if(type == 'photo') {
            var element = $('.i-photo');
            DR.log('a hello');
            initPhotoPop(element, id, image, title, cid, aid, gid, creator, stars, starred, imgheight, imgwidth);
        }
        if(type == 'note') {
            var element = $('.i-note');
            DR.log('a hello');
            initNotePop(element, id, title, story, cid, aid, gid, creator, stars, starred);
        }
        
        if(type == 'video') {
            var element = $('.i-video');
            DR.log('a hello');
            initVideoPop(element, id, vid, title, cid, aid, gid, creator, stars, starred);
        }
    }
    
    // This function is only called when a user enters KHV through a shared content link
    this.initSharedContent = function(type, id, title, cid, aid, gid, creator, stars, starred, vid, vidheight, vidwidth, story, image, imgheight, imgwidth) {
    	DR.log('Arrived through shared content ');
    	if(type == 'photo') {
            DR.log('GO OPEN PHOTO');
            var element = $('.i-photo');
            initPhotoPop(element, id, image, title, cid, aid, gid, creator, stars, starred, imgheight, imgwidth);
        }
        if(type == 'note') {
            DR.log('GO OPEN NOTE');
            var element = $('.i-note');
            initNotePop(element, id, title, story, cid, aid, gid, creator, stars, starred);
        }
    
        if(type == 'video') {
            DR.log('GO OPEN VIDEO');
            var element = $('.i-video');
            var host = 'facebook';
            initVideoPop(element, id, vid, title, cid, aid, gid, creator, stars, starred, host, vidheight, vidwidth);
        }
    }
    
    function initPopovers(){
        //Hide FB comments if broswer is IE8 or lower
        /*var browser = parseInt($.browser.version, 10);

        if ($.browser.msie && browser < 10) {
        DR.log('Hide comments');
        $('.i-pop-commentbox').hide();
         //DR.log('Broswer version: '+ parseInt($.browser.version, 10));
        }*/
        
        if(window.Arcade.user.state.userId == '-1') {
            $('.i-remove-btn').hide();
        }
        
        /* All popovers */
        $('.i-pop').hide();
        $('.i-pop').css('height',$(document).height());
        $('.i-pop-close').click(function(){
            $('.i-pop').hide();
            $('.i-pop-video iframe').attr('src', '');
        });
        
        $('.i-media-content').hide();

        /* Sign in and registration */
        // Validation
        $("#i-auth-reg-form").validate({
            rules: {
                'reg-fullname': {
                    required: true
                },
                'reg-email': {
                    required: true,
                    email: true
                },
                'reg-password': {
                    required: true,
                    minlength: 6
                },
                'reg-password-repeat': {
                    required: true,
                    equalTo: "#reg-password"
                },
                'reg-terms': {
                    required: true
                }
            },
            
            messages: {
                'reg-fullname': {
                    required: ''
                },
                'reg-email': {
                    required: '',
                    email: ''
                },
                'reg-password': {
                    required: '',
                    minlength: ''
                },
                'reg-password-repeat': {
                    required: '',
                    equalTo: ""
                },
                'reg-terms': {
                    required: '*Required'
                }
            }
            
        });
        $("#i-auth-sign-form").validate({
            rules: {
                'email': {
                    required: true,
                    email: true
                },
                'password': {
                    required: true
                }
            },
            
            messages: {
                'email': {
                    required: '',
                    email: ''
                },
                'password': {
                    required: '',
                    minlength: ''
                }
            }
        });
        $("#i-forgotpwd-form").validate({
            rules: {
                'email': {
                    required: true,
                    email: true
                }
            }
        });
        
        /** Community Request Form **/
        $('#i-submit-cmt-form').validate({
            rules: {
                'cmt-province': {
                    required: true
                },
                'cmt-city': {
                    required: true
                },
                'cmt-rink': {
                    required: true
                },
                'cmt-address': {
                    required: true
                },
                'cmt-postal': {
                    required: true
                }
            }
        });
        
        /* Authentication */
        $('.i-register').click(function(){
            $('.i-pop-reg').show();
            positionPopup('.i-pop-reg .i-pop-inner');
        });
        $('.i-signin').click(function(){
            $('.i-pop-signin').show();
            positionPopup('.i-pop-signin .i-pop-inner');
        });
        $('.i-signin-forgot').click(function(){
            $('.i-pop-signin').hide();
            $('.i-pop-forgotpwd').show();
            positionPopup('.i-pop-forgotpwd .i-pop-inner');
        });
        
        $('.i-video').unbind().click(function(e){
            e.preventDefault();
            getMediaData($(this));
            //initVideoPop($(this));
        });
        
        /* Photo */
        $('.i-photo').unbind().click(function(e) {
            e.preventDefault();
            getMediaData($(this));
            //initPhotoPop($(this));
        });
        
        /* Note */
        $('.i-note').unbind().click(function(e) {
            e.preventDefault();
            getMediaData($(this));
            //initNotePop($(this));
        });

        /* Mission expand */
        $('.i-mission-expand').unbind().click(function(e) {
            e.preventDefault();
            $("#cmt li.expanded-list").show();
            $("$this").hide();
        });

        /* Early bird */
        var options = {
            'maxCharacterSize': 1000,
            'originalStyle': 'popup-textarea-info',
            'warningStyle' : 'popup-textarea-warning',
            'warningNumber': 100,
            'displayFormat' : '#input / #max characters'
        };
        $('.i-pop-early textarea').textareaCount(options);

        /* Uploading Content */
        $('.i-msn-upload').unbind().click(function(e) {
            e.preventDefault();
            $('.i-pop').hide();
            
			var id = $('.i-data-msnid', this).val();
			if(id == undefined) {
				id = 'none';
			}
			$('#pop-upload-pic').hide();
			$('#pop-upload-note').hide();
			$('#pop-upload-vid').hide();
			DR.log('MSN ID Before: ' + id);
			$('.i-pop-upload').show();
			positionPopup('.i-pop-upload .i-pop-inner');
			initUploadPop(id);
        });
        
        if ('user_registered' in window.Arcade.events) {
            // This user just filled out the register form - so they wanted to upload - trigger upload form
            $('.i-msn-upload').click();
        }
        
        //Character counter/limiter for the note title/message popup    
        var counterOptions = {
            'maxCharacterSize': 50,
            'originalStyle': 'popup-textarea-info',
            'warningStyle' : 'popup-textarea-warning',
            'warningNumber': 10,
            'displayFormat' : '#input / #max characters'
        };
        $('.i-pop-upload #upld-note-title').textareaCount(counterOptions);
        $('.i-pop-upload #upld-pic-title').textareaCount(counterOptions);
        $('.i-pop-upload #upld-vid-title').textareaCount(counterOptions);
            
        counterOptions = {
            'maxCharacterSize': 4000,
            'originalStyle': 'popup-textarea-info',
            'warningStyle' : 'popup-textarea-warning',
            'warningNumber': 100,
            'displayFormat' : '#input / #max characters'
        };
        $('.i-pop-upload textarea').textareaCount(counterOptions);
    }
    
    function setUpClosePopover() {
        $('.i-pop').click(function(){
            $('.i-pop').hide();
            $('.i-pop-video iframe').attr('src', '');
        });
        $('.i-pop-inner').click(function(e){
            e.stopPropagation();
        });
    }
    
    function getMediaData(element) {
        DR.log('element: ' + element);
        var id = $('.i-data-id', element).val();
        var image = $('.i-data-picture', element).val();
        var title = $('.i-data-title', element).val();
        var story = $('.i-data-note', element).val();
        var cid = $('.i-data-cid', element).val();
        var aid = $('.i-data-aid', element).val();
        var gid = $('.i-data-gid', element).val();
        var creator = $('.i-data-creator', element).val();
        var stars = $('.i-data-stars', element).val();
        var starred = $('.i-data-starred', element).val();
        var imgheight = $('.i-data-picture-height', element).val();
        var imgwidth = $('.i-data-picture-width', element).val();
        var vidheight = $('.i-data-video-height', element).val();
        var vidwidth = $('.i-data-video-width', element).val();
        var vid = $('.i-data-videoid', element).val();
        var host = $('.i-data-host', element).val();
        var type = $('.i-data-type', element).val();
        
        /*if (KHV.data.cid == gid) {
            DR.log('Allow user to rate content');
            $('.i-pop-media .i-star-container').html("<span class='i-star pop-star'><input type='hidden' value='' class='i-data-itemid' /></span>");
        }*/
        
        if(type == 'photo') {
            DR.log('GO OPEN PHOTO');
            initPhotoPop(element, id, image, title, cid, aid, gid, creator, stars, starred, imgheight, imgwidth);
        }
        if(type == 'note') {
            DR.log('GO OPEN NOTE');
            initNotePop(element, id, title, story, cid, aid, gid, creator, stars, starred);
        }
    
        if(type == 'video') {
            DR.log('GO OPEN VIDEO');
            initVideoPop(element, id, vid, title, cid, aid, gid, creator, stars, starred, host, vidheight, vidwidth);
        }
    }
    
    function initVideoPop(element, id, vid, title, cid, aid, gid, creator, stars, starred, host, vidheight, vidwidth){
            $('.i-media-content').hide();
            
            DR.log('video start');
            
            // Set up content
            //TODO This won't be a youtube video
            if(host == "youtube") {
                $('.i-pop-video iframe').attr('src', '//www.youtube.com/embed/' + vid + '?rel=0&autoplay=1&wmode=transparent');
                $('.i-pop-media .i-pop-stars').hide();
                $('.i-pop-media .i-star').hide();
            } else {
                $('.i-pop-video iframe').attr('src', 'http://www.facebook.com/v/' + vid).attr('height', vidheight).attr('width', vidwidth);
                /* TODO: Probably don't need this, but just to make sure the stars show even after a user views a main video */
                $('.i-pop-media .i-pop-stars').show();
                $('.i-pop-media .i-star').show();
            }
            
            $('.i-pop-media .i-pop-video-title').html('Title: ' + title);
            $('.i-pop-media .i-pop-video-creator').html('by ' + creator);
            $('.i-pop-media .i-pop-stars').html('<span class="i-pop-stars-num">' + stars + '</span><span class="pop-stars-img"></span>');
            if (starred == 1) {
                $('.i-pop-media .i-star').addClass('highlight');
            } else {
                $('.i-pop-media .i-star').removeClass('highlight');
                DR.log('starred: ' + starred);
            }
            
            /* Also hides video's in album 
            if (stars == false) {
                DR.log('This is a main page video');
                $('.i-pop-media .i-pop-stars').hide();
                $('.i-pop-media .i-star').hide();
            }*/
            
            $('.i-pop-media .i-data-itemid').val(id);
            $('.i-pop-media .i-data-fbShare').val('shareVideo');
            $('.i-pop-media .i-data-returnLink').val(window.Arcade.host + 'community/album/aid/' + aid + '/content/' + cid);
            
            //Makes the like button unique for each piece of content
            $('.i-pop-media .i-like').attr('href', window.Arcade.host + 'community/album/aid/' + aid + '/content/' + cid);

            //Clears and repopulates this div make the comments unique to the content
            $('.i-pop-media .i-fb-commentbox').html("<fb:comments href='" + window.Arcade.host + "community/album/aid/" + aid + "/content/" + cid +  "' num-posts='5' title='FB Comments' width='762' simple='true' reverse='false' publish_feed='true' canpost='true' id='commentbox' class='i-pop-commentbox pop-commentbox fb-comments'></fb:comments>");
            
            //If user is not a member of the community/album, do not let them post comments
            DR.log('groupid: ' + KHV.data.cid);
            if(KHV.data.cid != gid) {
                DR.log('change canpost');
                $('.i-pop-media .i-fb-commentbox').empty();
            }
            
            // Initiates the left/right media navigation
            mediaNavi(element);
            
            $('.i-remove-btn').unbind().click(function() {
                removeContentPopover(id);
            });
            
            //using single media popup
            $('#pop-media').show();
            $('.i-pop-video').show();
            positionPopup('.i-pop-media .i-pop-inner');
            //Parses and renders all XFBML on the page without having to refresh(CommentBox or Like buttons in popup will not load properly without this)
             FB.XFBML.parse();
    }
    
    function initPhotoPop(element, id, image, title, cid, aid, gid, creator, stars, starred, imgheight, imgwidth) {
        $('.i-media-content').hide();
        
        DR.log('show photo now');
        
        //Fills in the different elements in the photo popup based on data above
        $('.i-pop-picture img').attr('src', image).attr('width', imgwidth).attr('height', imgheight );
        
        $('.i-pop-picture-title').html(title);
        $('.i-pop-media .i-pop-commentbox').attr('href', window.Arcade.host + '' + cid);
        $('.i-pop-media .i-pop-picture-creator').html('by ' + creator);
        $('.i-pop-media .i-pop-stars').html('<span class="i-pop-stars-num">' + stars + '</span><span class="pop-stars-img"></span>');
        if (starred == 1) {
            $('.i-pop-media .i-star').addClass('highlight');
            DR.log('starred: ' + starred);
        } else {
            $('.i-pop-media .i-star').removeClass('highlight');
            DR.log('starred: ' + starred);
        }
        $('.i-pop-media .i-data-itemid').val(id);
        $('.i-pop-media .i-data-fbShare').val('sharePhoto');
        $('.i-pop-media .i-data-returnLink').val(window.Arcade.host + 'community/album/aid/' + aid + '/content/' + cid);
        
        //Makes the like button unique for each piece of content
        $('.i-pop-media .i-like').attr('href', window.Arcade.host + 'community/album/aid/' + aid + '/content/' + cid);
        
        //Clears and repopulates this div make the comments unique to the content
        $('.i-pop-media .i-fb-commentbox').html("<fb:comments href='" + window.Arcade.host + "community/album/aid/" + aid + "/content/" + cid +  "' num-posts='5' title='FB Comments' width='762' simple='true' reverse='false' publish_feed='true' canpost='true' id='commentbox' class='i-pop-commentbox pop-commentbox fb-comments'></fb:comments>");
        
        //If user is not a member of the community/album, do not let them post comments
        DR.log('groupid: ' + KHV.data.cid);
        if(KHV.data.cid != gid) {
            DR.log('change canpost');
            $('.i-pop-media .i-fb-commentbox').empty();
        } 
        
        // Initiates the left/right media navigation
        mediaNavi(element);
        
        // Function that shows a popup to request removal of content
        $('.i-remove-btn').unbind().click(function() {
            removeContentPopover(id);
        });
        
        //using single media popup
        $('#pop-media').show();
        $('.i-pop-picture').show();
        positionPopup('.i-pop-media .i-pop-inner');
        //Parses and renders all XFBML on the page without having to refresh(CommentBox or Like buttons in popup will not load properly without this)
         FB.XFBML.parse();
    }
    
    function initNotePop(element, id, title, story, cid, aid, gid, creator, stars, starred) {
        $('.i-media-content').hide();
        
        // Fills in elements in note popup based off data above
        $('.i-pop-note-title').html(title);
        $('.i-pop-note-story').html(story);
        $('.i-pop-media .i-pop-note-creator').html('by ' + creator);
        $('.i-pop-media .i-pop-stars').html('<span class="i-pop-stars-num">' + stars + '</span><span class="pop-stars-img"></span>');
        
        // Checks to see if the content has been previously starred by the user and acts accordingly
        if (starred == 1) {
            $('.i-pop-media .i-star').addClass('highlight');
            DR.log('starred: ' + starred);
        } else {
            $('.i-pop-media .i-star').removeClass('highlight');
            DR.log('starred: ' + starred);
        }
        $('.i-pop-media .i-data-itemid').val(id);
        $('.i-pop-media .i-data-fbShare').val('shareNote');
        $('.i-pop-media .i-data-returnLink').val(window.Arcade.host + 'community/album/aid/' + aid + '/content/' + cid);
        
        //Makes the like button unique for each piece of content
        $('.i-pop-media .i-like').attr('href', window.Arcade.host + 'community/album/aid/' + aid + '/content/' + cid);
        
        //Clears and repopulates this div make the comments unique to the content
        $('.i-pop-media .i-fb-commentbox').html("<fb:comments href='" + window.Arcade.host + "community/album/aid/" + aid + "/content/" + cid +  "' num-posts='5' title='FB Comments' width='762' simple='true' reverse='false' publish_feed='true' canpost='true' id='commentbox' class='i-pop-commentbox pop-commentbox fb-comments'></fb:comments>");
        
        //If user is not a member of the community/album, do not let them post comments
        DR.log('groupid: ' + KHV.data.cid);
        if(KHV.data.cid != gid) {
            DR.log('change canpost');
            $('.i-pop-media .i-fb-commentbox').empty();
        } 
        
        //Initiates the navigation for media content
        mediaNavi(element);
        
        // Function that shows a popup to request removal of content
        $('.i-remove-btn').unbind().click(function() {
            removeContentPopover(id);
        });
        
        //using single media popup
        $('#pop-media').show();
        $('.i-pop-note').show();
        positionPopup('.i-pop-media .i-pop-inner');
        //Parses and renders all XFBML on the page without having to refresh(CommentBox or Like buttons in popup will not load properly without this)
         FB.XFBML.parse();
    }
    
    function removeContentPopover(content) {
        // Makes sure the user selected an option before sending
        $("#i-remove-media-form").validate({
            rules: {
                'media-reason': {
                    required: true
                }
            },
            
            messages: {
                'media-reason': {
                    required: '*Please select a reason before submitting'
                }
            }
        });
        
        DR.log('content: ' + content);
        // Fills in the hidden input with the contents id to send to the backend for removal review
        $('.i-data-removeId').val(content);
        $('.i-pop').hide();
        $('.i-pop-remove').show();
        positionPopup('.i-pop-remove .i-pop-inner');
    }
    
    function initSearchMethodsPop(element) {
        $('#pop-search-methods').show();
        positionPopup('.i-pop-search-methods .i-pop-inner');
    }
    
    function mediaNavi(type) {
        // Uses the title attribute on the li elements to detect what type of media content the next/prev li's are and init's the proper function
        // Used title attribute because class has too many different values for each li to be used and ID's must be unique
        DR.log('TyPe: ' + type);
        if(type.prev('.i-media').length > 0){
            $('.i-pop-prev').removeClass('disabled').unbind().click(function(){
                getMediaData(type.prev('.i-media'));
            });
        } else {
            $('.i-pop-prev').addClass('disabled').unbind();
        }
        if(type.next('.i-media').length > 0){
            $('.i-pop-next').removeClass('disabled').unbind().click(function(){
                getMediaData(type.next('.i-media'));
            });
        } else {
            $('.i-pop-next').addClass('disabled').unbind();
        }
    }
    
    function initUploadPop(msnid) {
        DR.log('MSN ID: ' + msnid);
        
        $('.i-data-msntag').val(msnid);
        //Clear Fields
        $('#upld-pic-file').val('');
        $('#upld-pic-title').val('');
        $('#upld-note-title').val('');
        $('#upld-note-msg').val('');
        
        // The input file type is difficult to make significant css adjustments too. So I have a fake one that looks nicer and the function below changes the fake input field when the real(hidden) one changes.
        var file = '';
        //For Photos
        $('#upld-pic-file').change(function() {
            DR.log('Change Photo!');
            file = $('#upld-pic-file').attr('value');
            //Browsers add fakepath when you get the val through js and reoutput it, this line removes that bit of text 
            newFile = file.replace("C:\\fakepath\\", "");
            DR.log('file: ' + newFile);
            $('#fakefilepc').val(newFile);
        });
        
        //For Videos
        $('#upld-vid-file').change(function() {
            DR.log('Change Video!');
            file = $('#upld-vid-file').attr('value');
            //Browsers add fakepath when you get the val through js and reoutput it, this line removes that bit of text 
            newFile = file.replace("C:\\fakepath\\", "");
            DR.log('file: ' + newFile);
            $('#fakevideopc').val(newFile);
        });
        
        // Get's upload type and hides other fields(Photo or Note)
        var val = $('.i-data-uploadtype').val();
        uploadContent(val);
        
        // Hides mission 3 option if user already had note open on page refresh
        /*if(val == 'note') {
            DR.log('hide msn3');
            $('.i-pop-upload-note .i-msn3').hide();
        }*/

		//Change the mission in te dropdown based on what mission the user is viewing
		if(KHV.data.msn != 0) {
			DR.log('mission: ' + KHV.data.msn);
			$('.i-data-msntag').val(KHV.data.msn);
		}
    
        //Changes the shown content based on which type user selects from drop down
        $('.i-data-uploadtype').change(function() {
            val = $(this).val();
            DR.log('type: ' + val);
            // Hides mission 3 if user changes the type to note
            if(val == 'note') {
                DR.log('hide msn3');
                $('.i-pop-upload-note .i-msn3').hide();
            }
            uploadContent(val);
        });
        
        //Validates upload forms
        $("#i-upld-pic-form").validate({
            rules: {
                'fakefilepc': {
                    required: true
                },
                'upld-pic-title': {
                    required: true
                }
            }
        });
        
        $("#i-upld-note-form").validate({
            rules: {
                'upld-note-title': {
                    required: true
                },
                'upld-note-msg': {
                    required: true
                }
            }
        });
        
        $('#i-upld-vid-form').validate({
            rules: {
                'fakevideopc': {
                    required: true
                },
                'upld-vid-title': {
                    required: true
                }
            }
        });
    }
    
    function uploadContent(type) {
        //Hides and shows sections of the popup based on upload type user selects
        if(type == 'picture') {
            $('.i-required').hide();
            $('#pop-upload-note').hide();
            $('#pop-upload-vid').hide();
            $('#pop-upload-pic').show();
        } else if(type == 'note') {
            $('.i-required').hide();
            $('#pop-upload-pic').hide();
            $('#pop-upload-vid').hide();
            $('#pop-upload-note').show();
        } else if(type == 'video') {
            $('.i-required').hide();
            $('#pop-upload-note').hide();
            $('#pop-upload-pic').hide();
            $('#pop-upload-vid').show();
        } else if(type == 'none') {
            $('#pop-upload-pic').hide();
            $('#pop-upload-note').hide();
            $('#pop-upload-vid').hide();
            $('.i-required').hide();
        } else {
            DR.log("If your seeing this, something is broken");
        }
    }
    
    function helpPopover(id, config){
        DR.log('Help popup: ' + id);
        
        var lang = KHV.en.events;
        if (window.Arcade.user.state.language == 'fr') {
            lang = KHV.fr.events;
        }
        
        if(window.Arcade.user.state.community){
            lang[id].txt = (lang[id].txt).replace("<COMMUNITY_NAME>", "<strong>" + KHV.arenaData[window.Arcade.user.state.community].name + "</strong>");
        }
        
        var config = config ? config : {};
        config.btn1Function = config.btn1Function ? config.btn1Function : function(){ $('.i-pop-help').hide(); };
        
        $('.i-pop-help-header').text(lang[id].ttl);
        $('.i-pop-help-message').html(lang[id].txt);
        
        /* Buttons */
        $('.i-pop-help-btn1').unbind('click').click(config.btn1Function);
        $('.i-pop-help-btn1 span').text(lang[id].btn1Txt);
        if(config.btn2Function){
        DR.log('showing button 2' + lang[id].btn2Txt);
            $('.i-pop-help-btn2').show().unbind('click').click(config.btn2Function);
            $('.i-pop-help-btn2 span').text(lang[id].btn2Txt);
        } else {
            $('.i-pop-help-btn2').hide();
        }
        if(config.btn3Function){
            $('.i-pop-help-btn3').show().unbind('click').click(config.btn3Function);
            $('.i-pop-help-btn3 span').text(lang[id].btn3Txt);
        } else {
            $('.i-pop-help-btn3').hide();
        }
        
        $('.i-pop-help').show();
        positionPopup('.i-pop-help .i-pop-inner');
    }
    
    function positionPopup(selector, additionalOffset){
        additionalOffset = additionalOffset ? additionalOffset : 0;
        var popHeight = $(selector).outerHeight() + additionalOffset;
        var screenHeight = $(window).scrollTop() + $(window).height();
        
        DR.log('popup height: ' + popHeight);
        DR.log('screen height: ' + screenHeight);
        
        if(screenHeight > popHeight) {
            DR.log('Small Popup');
            $(selector).css('top', Math.floor($(window).scrollTop() + $(window).height()/2 - $(selector).outerHeight()/2 + additionalOffset + 8));
        } else {
            DR.log('Big Popup');
            $(selector).css('top', Math.floor($(window).scrollTop() + 25));
        }
        
        $(selector).css('left', Math.floor($(window).width()/2 - $(selector).outerWidth()/2));
        
        setUpClosePopover();
    }
    
    function initSocial(selector){
        $(selector).each(function(index){
            var likeURL = $('.i-data-likeURL', $(this)).val(),
                shareURL = $('.i-data-shareURL', $(this)).val(),
                shareType = $('.i-data-shareType', $(this)).val(),
                sharePst = KHV.data.shortpostal,
                returnURL = $('.i-data-returnURL', $(this)).val(),
                invite = $('.i-data-invite', $(this)).val(),
                htmlString = '';
            
            if(invite){
                htmlString += '<a class="social-btn social-invite i-invite"></a>';
            }
            if(shareURL){
                htmlString += '<a href="https://twitter.com/intent/tweet?text=%20%23krafthockeyville' + sharePst + '&url=' + encodeURI(shareURL) + '" class="i-tweet social-btn social-tweet"></a> ';
            }
            if(shareType) {
            	htmlString += '<a class="i-share social-btn social-share"><input type="hidden" class="i-data-fbShare" value="' + shareType + '"/><input type="hidden" class="i-data-returnLink" value="'+ returnURL +'"/></a> ';
            }
            if(likeURL){
                //DR.log('like url: ' + likeURL);
                htmlString += '<fb:like href="' + likeURL + '" send="false" layout="button_count" width="80" show_faces="false" action="like" font="arial" class="i-like"></fb:like>';
            }
            /*if(returnURL){
                htmlString += '<input type="hidden" class="i-data-returnLink" val="'+ returnURL +'"/>';
            }*/
            $(this).html(htmlString);

            // Share button binding
            $('.i-share', $(this)).unbind().click(function() {
        
                if (window.Arcade.user.state.type != 'facebook') {
                    helpPopover('notFbShare', {
                        btn1Function : function(){
                            DR.Facebook.login();
                            DR.log('Facebook login');
                            $('.i-pop-help').hide();
                        }
                    });
                } else {
                    //Universal share button that changes based on what type of content the user is trying to share
                    type = $('.i-data-fbShare', $(this)).val();
                    returnLink = $('.i-data-returnLink', $(this)).val();
                    DR.log('link in khv.js: ' + returnLink);
                    DR.log('Facebook user ' + type);
                    DR.Social.feed(type, null, returnLink);
                }
            });
            
            // Twitter button binding
            $('.i-tweet', $(this)).unbind().click(function(){
                if (!window.Arcade.user.state.loggedIn){
                    DR.log('User needs to be signed in');
                    helpPopover('signIn',{
                        btn1Function : function(){
                            DR.Facebook.login();
                            DR.log('Facebook login');
                            $('.i-pop-help').hide();
                        },
                        btn2Function : function(){
                            $('.i-pop-help').hide();
                            $('.i-pop-signin').show();
                            positionPopup('.i-pop-signin .i-pop-inner');
                        },
                        btn3Function : function(){
                            $('.i-pop-help').hide();
                            $('.i-pop-reg').show();
                            positionPopup('.i-pop-reg .i-pop-inner');
                        }
                    });
                    return false;
                } else {
                    newwindow = window.open($(this).attr('href'),'twitterpopup','height=300,width=500,top=200,left=400');
                    if (window.focus) {newwindow.focus();}
                    return false;
                }
            });
            
            //Invite Friends
            $('.i-invite').unbind().click(function() {
                if (window.Arcade.user.state.type != 'facebook') {
                    helpPopover('notFbInvite', {
                        btn1Function : function(){
                            DR.Facebook.login();
                            DR.log('Facebook login');
                            $('.i-pop-help').hide();
                        }
                    });
                } else {
                    DR.Social.invites('invite');
                }
            });
        });
        
        // XFBML like button conversion for post-page load instances
        if(typeof FB != 'undefined'){
            FB.XFBML.parse();
        }
    }
}

KHV.fr = {};
KHV.fr.events = {
    /* Reg/Sign in Error Messages */
    'usernameError' : {
        ttl: "Adresse électronique erronnée",
        txt: "<p>L'adresse électronique renseignée n'est pas valide. Merci de la vérifier et de réessayer.</p>",
        btn1Txt: 'Continuer'
    },
    'passwordError' : {
        ttl: "Mot de passe erronné",
        txt: "<p>Le mot de passe renseigné n'est pas valide. Merci d'essayer à nouveau (assurez-vous que la touche MAJ de votre clavier n'est pas activée).</p>",
        btn1Txt: 'Continuer'
    },
    'registerError' : {
        ttl: "Adresse électronique déjà utilisée",
        txt: "<p>Cette adresse électronique est déjà associé à un compte. Merci de vous identifier avec.</p>",
        btn1Txt: 'Continuer'
    },
    'useFacebook' : {
        ttl: "Merci de vous connecter avec Facebook",
        txt: "<p>Il semble que cette adresse se soit déjà connectée précédemment en utilisant Facebook. Merci de vous identifier avec Facebook.</p>",
        btn1Txt: 'Continuer'
    },
    'forgotPwdEmailed' : {
        ttl: "Un courriel vient de vous être expédié",
        txt: "<p>Merci de consulter votre boîte aux lettres. Quelques minutes peuvent être nécessaires avant de recevoir notre message.</p>",
        btn1Txt: 'CONTINUER'
    },
    'forgotPwdChanged' : {
        ttl: "Modification effectuée!",
        txt: "<p>Votre mot de passe a bien été changé.</p>",
        btn1Txt: 'CONTINUER'
    },
    'internalError' : {
        ttl: "Erreur interne",
        txt: "<p>Nous rencontrons actuellement des problèmes techniques. Merci d'essayer à nouveau dans quelques minutes.</p>",
        btn1Txt: 'Continuer'
    },
    
    /* User clicks */
    'signIn' : {
        ttl: "Bienvenue dans Kraft Hockeyville 2012.",
        txt: "<p>L'aventure commence ici pour être couronnée la ville la plus passionnée de hockey du Canada ! Connectez-vous avec Facebook ou enregistrez votre adresse électronique et entrez dans la compétition. Merci de votre participation et bonne chance !</p>",
        btn1Txt: 'SE CONNECTER AVEC FACEBOOK',
        btn2Txt: "S'IDENTIFIER",
        btn3Txt: "S'INSCRIRE"
    },
    'cantFindCommunity' : {
        ttl: "Êtes-vous certain que votre aréna n'est pas dans la liste?",
        txt: "<p>Plus de 2400 arénas sont déjà listés dans notre base de données. Si la recherche par nom ne donne rien, essayez de naviguer par province ou territoire.</p>",
        btn1Txt: "RECHERCHER PAR PROVINCE",
        btn2Txt: "FAIRE UNE DEMANDE D'AJOUT "
    },
    'notFbInvite' : {
        ttl: "C'est encore plus de fun avec les amis!",
        txt: "<p>Vous devez être connecté avec Facebook pour inviter des amis.</p>",
        btn1Txt: 'INVITER DES AMIS'
    },
    'notFbShare' : {
        ttl: "Partagez votre soutien!",
        txt: "<p>Vous devez être connecté avec Facebook pour partager du contenu.</p>",
        btn1Txt: 'SE CONNECTER À FACEBOOK'
    },
    'notJoinedCommunity' : {
        ttl: "Rejoignez le jeu...",
        txt: "<p>Afin de concourir pour le titre et le prix de Kraft Hockeyville 2012, vous devez rejoindre la page de votre communauté.</p>",
        btn1Txt: 'TROUVER UNE COMMUNAUTÉ'
    },
    //Early Bird
    'unqualifiedCommunity' : {
        ttl: "Votre communauté a besoin de vous!",
        txt: "<p>Votre communauté doit publier une histoire ET une image dans la Mission 1 avant de participer au concours Early Bird.</p>",
        btn1Txt: 'VOIR LES MISSIONS'
    },
    'earlyBirdFBConfirm' : {
        ttl: "Partagez la bonne nouvelle!",
        txt: "<p>Votre contribution a bien été enregistrée. Vous êtes éligible pour remporter le prix concours d'Early Bird. Kraft Hockeyville de 10 000 $, dites-le à vos amis!</p>",
        btn1Txt: 'PARTAGER',
        btn2Txt: 'RETOURNER À MA COMMUNAUTÉ'
    },
    'earlyBirdEmailConfirm' : {
        ttl: "Bien joué!",
        txt: "<p>Vous êtes éligible pour remporter le prix Early Bird Kraft Hockeyville de 10 000 $.</p>",
        btn1Txt: 'RETOURNER À MA COMMUNAUTÉ'
    },
    'earlyBirdReminder' : {
        ttl: "Félicitations!",
        txt: "<p>Votre aréna qualifié pour Kraft Hockeyville 2012! Maintenant, vous pouvez gagnez 10 000 $ en nouvel équipement pour votre Association de Hockey Mineur! </p>",
        btn1Txt: 'EN SAVOIR PLUS'        
    },
    'enteredEarly' : {
        ttl: "Désolé!",
        txt: "<p>Vous vous êtes déjà enregistré pour le concours Early Bird.</p>",
        btn1Txt: 'CONTINUER'
    },
    'joinCommunity' : {
        ttl: "Allez l'équipe!",
        txt: "<p>Rejoignez la page d'une communauté et partagez votre passion pour le hockey tout en affirmant votre esprit d'équipe.</p>",
        btn1Txt: 'REJOINDRE MAINTENANT!',
        btn2Txt: 'NON MERCI'
    },
    
    /* Events */
    'newFBUser' : {
        ttl: "Merci de vous être enregistré!",
        txt: "<p>Il se passe beaucoup de choses ici...</p><h3>Partagez votre passion pour le hockey!</h3><p>Annoncez à vos amis que vous participez à Kraft Hockeyville 2012.</p>",
        btn1Txt: 'PARTAGER',
        btn2Txt: 'CONTINUER'
    },
    'newEmailUser' : {
        ttl: "Merci de vous être connecté!",
        txt: "<p>Il se passe beaucoup de choses ici...</p><h3>Entrez dans le jeu!</h3><p>Rejoignez la page de votre communauté et concourez pour le titre et le prix de Kraft Hockeyville 2012.</p>",
        btn1Txt: 'TROUVER UNE COMMUNAUTÉ '
    },
    'joinedGroupFB' : {
        ttl: "Merci pour votre support!",
        txt: "<p>Vous avez rejoint la communauté de <COMMUNITY_NAME></p><h3>Partagez votre passion pour le hockey!</h3><p>Annoncez à vos amis que vous avez rejoint notre communauté pour concourir au titre de Kraft Hockeyville 2012.</p><h3>Engagez-vous et amusez-vous!</h3><p>Soumettez votre contenu pour soutenir notre communauté dans sa course pour la victoire! Participez à des missions et remportez des trophées.</p>",
        btn1Txt: 'PARTAGER',
        btn2Txt: 'CONTINUER'
    },
    'joinedGroupEmail' : {
        ttl: "Merci pour votre support!",
        txt: "<p>Vous avez rejoint la communauté de <COMMUNITY_NAME></p><h3>Engagez-vous et amusez-vous!</h3><p>Soutenez-nous et contribuez à faire remporter le titre de Kraft Hockeyville 2012 à notre communauté.</p><ul><li>Soumettez vos histoires, images et vidéos</li><li>Participez à des missions et gagnez des trophées</li><li>Notez les contributions de notre communauté</li><li>Partagez notre passion sur Facebook et Twitter et incitez vos amis à faire de même!</li></ul>",
        btn1Txt: 'CONTINUER'
    },
    'requestGroup' : {
        ttl: "Votre demande a bien été prise en compte!",
        txt: "<p>Nous traiterons votre demande dans un délai de 3 jours ouvrés. En cas de problème, nous vous contacterons directement par courrier électronique.</p>",
        btn1Txt: 'CONTINUER'
    },
    'msn3CompleteFB' : {
        ttl: "Merci de patienter",
        txt: "<p>Votre contribution est en cours de publication. Quelques minutes peuvent être nécessaires avant de la voir apparaitre dans la galerie.</p>",
        btn1Txt: 'PARTAGER',
        btn2Txt: 'FERMER'
    },
    'msn3CompleteEmail' : {
        ttl: "Merci de patienter",
        txt: "<p>Votre contribution est en cours de publication. Quelques minutes peuvent être nécessaires avant de la voir apparaitre dans la galerie.</p>",
        btn1Txt: 'FERMER'
    },
    'upload1NoteFB' : {
        ttl: "Merci de patienter",
        txt: "<p>Votre contribution est en cours de publication. Quelques minutes peuvent être nécessaires avant de la voir apparaitre dans la galerie.</p><h3><span class='trophies trophy-0-real'></span>Félicitations!</h3><p>Votre histoire vous fait remporter la Coupe de Conception Bay South, nommée ainsi en l'honneur du gagnant de Kraft Hockeyville 2011.</p><p class='post-trophy'>Merci pour le soutien de votre communauté! Bien joué, continuez ainsi!</p><br/><p>Partagez votre performance et votre passion pour le hockey avec vos amis!</p>",
        btn1Txt: 'PARTAGER',
        btn2Txt: 'FERMER'
    },
    'upload1NoteEmail' : {
        ttl: "Merci de patienter",
        txt: "<p>Votre contribution est en cours de publication. Quelques minutes peuvent être nécessaires avant de la voir apparaitre dans la galerie.</p><h3><span class='trophies trophy-0-real'></span>Félicitations!</h3><p>Votre histoire vous fait remporter la Coupe de Conception Bay South, nommée ainsi en l'honneur du gagnant de Kraft Hockeyville 2011.</p><p class='post-trophy'>Merci pour le soutien de votre communauté! Bien joué, continuez ainsi!</p>",
        btn1Txt: 'FERMER'
    },
    'upload1PhotoFB' : {
        ttl: "Merci de patienter",
        txt: "<p>Votre contribution est en cours de publication. Quelques minutes peuvent être nécessaires avant de la voir apparaitre dans la galerie.</p><h3><span class='trophies trophy-1-real'></span>Félicitations!</h3><p>Votre photo vous fait remporter le Trophée Dundas, nommé ainsi en honneur du gagnant de Kraft Hockeyville 2010.</p><p class='post-trophy'>Merci pour le soutien de votre communauté! Bien joué, continuez ainsi!</p><br/><p>Partagez votre performance et votre passion pour le hockey avec vos amis!</p>",
        btn1Txt: 'PARTAGER',
        btn2Txt: 'FERMER'
    },
    'upload1PhotoEmail' : {
        ttl: "Merci de patienter",
        txt: "<p>Votre contribution est en cours de publication. Quelques minutes peuvent être nécessaires avant de la voir apparaitre dans la galerie.</p><h3><span class='trophies trophy-1-real'></span>Félicitations!</h3><p>Votre photo vous fait remporter le Trophée Dundas, nommé ainsi en honneur du gagnant de Kraft Hockeyville 2010.</p><p class='post-trophy'>Merci pour le soutien de votre communauté! Bien joué, continuez ainsi!</p>",
        btn1Txt: 'FERMER'
    },
    'upload' : {
        ttl: "Merci pour le soutien de votre communauté!",
        txt: "<p>Votre contribution est en cours de publication. Nous vous prions de patienter, cela peut prendre quelques minutes avant qu'elle n'apparaisse sur le site. Vous serez tenu informé en cas de problème.</p>",
        btn1Txt: 'FERMER'
    }    ,
        'msn2CompleteFB' : {
            ttl: "C'est ça l'esprit d'équipe!",
            txt: "<h3><span class='trophies trophy-2-real'></span>Félicitations!</h3><p>En ajoutant votre nom au programme Kraft Food pour les Familles, vous remportez la Coupe Terrace, nommée ainsi en l'honneur du lauréat Kraft Hockeyville 2009.</p><br /><p class='post-trophy'>Partagez l'esprit du don et aidez Kraft à aider les familles!</p>",
            btn1Txt: 'PARTAGER',
            btn2Txt: 'FERMER'
        },
        'msn2CompleteEmail' : {
            ttl: "C'est ça l'esprit d'équipe!",
            txt: "<h3><span class='trophies trophy-2-real'></span>Félicitations!</h3><p>En ajoutant votre nom au programme Kraft Food pour les Familles, vous remportez la Coupe Terrace, nommée ainsi en l'honneur du lauréat Kraft Hockeyville 2009.</p><br/><p class='post-trophy'>Merci d'aider Kraft à faire en sorte que tout le monde puisse profiter des fêtes.</p>",
            btn1Txt: 'FERMER'
        },
        'msn3CompleteFB' : {
            ttl: "Merci de patienter",
            txt: "<p>Votre contribution est en cours de publication. Quelques minutes peuvent être nécessaires avant de la voir apparaitre dans la galerie.</p><h3><span class='trophies trophy-3-real'></span>Félicitations!</h3><p>Votre contribution vous fait remporter le Trophée Roberval, en l'honneur du lauréat Kraft Hockeyville 2008.</p><br/><p class='post-trophy'>Bien joué, continuez ainsi!</p><br/><p>Partagez votre action et votre esprit d'équipe avec vos amis!</p>",
            btn1Txt: 'PARTAGER',
            btn2Txt: 'FERMER'
        },
        'msn3CompleteEmail' : {
            ttl: "Merci de patienter",
            txt: "<p>Votre contribution est en cours de publication. Quelques minutes peuvent être nécessaires avant de la voir apparaitre dans la galerie.</p><h3><span class='trophies trophy-3-real'></span>Félicitations!</h3><p>Votre contribution vous fait remporter le Trophée Roberval, en l'honneur du lauréat Kraft Hockeyville 2008.</p><br/><p class='post-trophy'>Bien joué, continuez ainsi!</p>",
            btn1Txt: 'FERMER'
        },
        'msn4CompleteFB' : {
            ttl: "Merci d'être patient",
            txt: "<p>Votre contribution est en cours de publication. Les histoires et les photos peuvent prendre quelques minutes et les vidéos jusqu'à une heure avant d'être visibles dans la galerie.</p><h3><span class='trophies trophy-4-real'></span>Félicitations!</h3><p>Votre contribution vous fait remporter la Coupe North Bay, nommée ainsi en l'honneur du lauréat Kraft Hockeyville 2007.</p><p class='post-trophy'>Partagez votre réussite et incitez vos amis à faire de même pour gagner!</p>",
            btn1Txt: 'PARTAGER',
            btn2Txt: 'FERMER'
        },
        'msn4CompleteEmail' : {
            ttl: "Merci d'être patient",
            txt: "<p>Votre contribution est en cours de publication. Les histoires et les photos peuvent prendre quelques minutes et les vidéos jusqu'à une heure avant d'être visibles dans la galerie.</p><h3><span class='trophies trophy-4-real'></span>Félicitations!</h3><p>Votre contribution vous fait remporter la Coupe North Bay, nommée ainsi en l'honneur du lauréat Kraft Hockeyville 2007.</p><br/><p class='post-trophy'>Bien joué, continuez ainsi!</p>",
            btn1Txt: 'FERMER'
        },
        'msn5CompleteFB' : {
            ttl: "Merci d'être patient",
            txt: "<p>Votre contribution est en cours de publication. Les histoires et les photos peuvent prendre quelques minutes et les vidéos jusqu'à une heure avant d'être visibles dans la galerie.</p><h3><span class='trophies trophy-5-real'></span>Félicitations!</h3><p>Votre contribution vous fait remporter le convoité Trophée Salmon River, nommé ainsi en l'honneur du lauréat Kraft Hockeyville 2006.</p><p class='post-trophy'>Partagez votre réussite et incitez vos amis à faire de même pour gagner!</p>",
            btn1Txt: 'PARTAGER',
            btn2Txt: 'FERMER'
        },
        'msn5CompleteEmail' : {
            ttl: "Merci d'être patient",
            txt: "<p>Votre contribution est en cours de publication. Les histoires et les photos peuvent prendre quelques minutes et les vidéos jusqu'à une heure avant d'être visibles dans la galerie.</p><h3><span class='trophies trophy-5-real'></span>Félicitations!</h3><p>Votre contribution vous fait remporter le convoité Trophée Salmon River, nommé ainsi en l'honneur du lauréat Kraft Hockeyville 2006.</p><br/><p class='post-trophy'>Bien joué, continuez ainsi!</p>",
            btn1Txt: 'FERMER'
        },
        'popupBanner1FB' : {
            ttl: "Bienvenu cher débutant!",
            txt: "<p>Félicitations! Vous venez de remportez l'insigne de 'Débutant' pour votre implication dans Kraft Hockeyville 2012. Prochain grade : 'Meneur de jeu'!</p><br /><p>Partagez votre succès et votre passion pour le hockey avec vos amis.</p>",
            btn1Txt: 'PARTAGER',
            btn2Txt: 'FERMER'
        },
        'popupBanner2FB' : {
            ttl: "Vous êtes Meneur de jeu! Passez le mot!",
            txt: "<p>Félicitations! Vous remportez le grade de Meneur de jeu pour votre performance dans Kraft Hockeyville 2012. Prochain niveau... Capitaine adjoint!</p><p>Partagez votre réussite et votre passion pour le hockey avec vos amis.</p>",
            btn1Txt: 'PARTAGER',
            btn2Txt: 'FERMER'
        },
        'popupBanner3FB' : {
            ttl: "Un 'A' pour vos efforts!",
            txt: "<p>Félicitations! Vous remportez le grade de Capitaine adjoint pour votre performance dans Kraft Hockeyville 2012. Prochain niveau... Étoile!</p><p>Partagez votre réussite et votre passion pour le hockey avec vos amis.</p>",
            btn1Txt: 'PARTAGER',
            btn2Txt: 'FERMER'
        },
        'popupBanner4FB' : {
            ttl: "Étoile! Quel honneur!",
            txt: "<p>Félicitations! Vous remportez le grade d'Étoile pour votre performance dans Kraft Hockeyville 2012. Prochain niveau... Capitaine d'équipe!</p><p>Partagez votre réussite et votre passion pour le hockey avec vos amis.</p>",
            btn1Txt: 'PARTAGER',
            btn2Txt: 'FERMER'
        },
		'popupBanner5FB' : {
			ttl: "Montrez le chemin cher Capitaine !",
			txt: "<p>Félicitations! Vous remportez le grade de Capitaine d'équipe pour votre performance dans Kraft Hockeyville 2012. Prochain niveau... Meilleur marqueur!</p><p>Partagez votre réussite et votre passion pour le hockey avec vos amis.</p>",
			btn1Txt: 'PARTAGER',
			btn2Txt: 'FERMER'
		},
		'popupBanner6FB' : {
			ttl: "En tête du championnat !",
			txt: "<p>Je participe à Kraft Hockeyville 2012 et je viens d'obtenir le grade de Meilleur marqueur. Je suis maintenant en lice pour la plus haute distinction : JPU Régional ! Venez voir ça !</p><p>Partagez votre réussite et votre passion pour le hockey avec vos amis.</p>",
			btn1Txt: 'PARTAGER',
			btn2Txt: 'FERMER'
		}
};

KHV.en = {};
KHV.en.events = {
    /* Reg/Sign in Error Messages */
    'usernameError' : {
        ttl: "Incorrect Email",
        txt: "<p>The Email you entered is incorrect. Please check your spelling and try again.</p>",
        btn1Txt: 'Continue'
    },
    'passwordError' : {
        ttl: "Incorrect Password",
        txt: "<p>The password you entered is incorrect. Please check your spelling and try again (make sure CAPS lock is off).</p>",
        btn1Txt: 'Continue'
    },
    'registerError' : {
        ttl: "Email Already Exists",
        txt: "<p>Our records indicate this Email address is already registered to the site. Please login via email.</p>",
        btn1Txt: 'Continue'
    },
    'useFacebook' : {
        ttl: "Please Connect Using Facebook",
        txt: "<p>Our records indicate this email address has already used Facebook to connect to this site. Please connect via Facebook.</p>",
        btn1Txt: 'Continue'
    },
    'forgotPwdEmailed' : {
        ttl: "We Have Sent You an Email",
        txt: "<p>Please go to your inbox and look for our email. It may take a few minutes to arrive.</p>",
        btn1Txt: 'Continue'
    },
    'forgotPwdChanged' : {
        ttl: "Success!",
        txt: "<p>Your password has been changed.</p>",
        btn1Txt: 'Continue'
    },
    'internalError' : {
        ttl: "There Has Been An Error",
        txt: "<p>We are experiencing technical issues. Please try again in a few minutes.</p>",
        btn1Txt: 'Continue'
    },
    
    /* User clicks */
    'signIn' : {
        ttl: "Welcome to Kraft Hockeyville 2012.",
        txt: "<p>Your quest to be crowned Canada’s most passionate hockey town starts here! Please connect with Facebook or sign up with email for your shot at winning. Thanks for participating and good luck!</p>",
        btn1Txt: 'CONNECT WITH FACEBOOK',
        btn2Txt: 'LOGIN WITH EMAIL',
        btn3Txt: 'SIGN UP WITH EMAIL'
    },
    'cantFindCommunity' : {
        ttl: "Are you sure your arena isn't already listed?",
        txt: "<p>There are 2400+ arenas listed in our database. If you can't find your arena with the search tool, try clicking on a province or territory to view a full listing of arenas.</p>",
        btn1Txt: 'View provincial listings',
        btn2Txt: 'Complete request form'
    },
    'notFbInvite' : {
        ttl: "It's more fun with friends!",
        txt: "<p>You must connect via Facebook to invite friends</p>",
        btn1Txt: 'Invite friends'
    },
    'notFbShare' : {
        ttl: "Share your support!",
        txt: "<p>You must connect via Facebook to share content.</p>",
        btn1Txt: 'Connect via Facebook'
    },
    'notJoinedCommunity' : {
        ttl: "Join the game...",
        txt: "<p>You must find and join an arena's community page to compete for the coveted Kraft Hockeyville title and prize.</p>",
        btn1Txt: 'FIND A COMMUNITY'
    },
    //Early Bird
    'unqualifiedCommunity' : {
        ttl: "Your community needs your help!",
        txt: "<p>Your community must upload a story AND an image to Mission 1 before you can enter the Early Bird contest.</p>",
        btn1Txt: 'View Missions'
    },
    'earlyBirdFBConfirm' : {
        ttl: "Share the good news!",
        txt: "<p>Your entry has been received. Tell your friends you are eligible for Kraft Hockeyville's $10,000 Early Bird prize.</p>",
        btn1Txt: 'Share',
        btn2Txt: 'Go to My Community'
    },
    'earlyBirdEmailConfirm' : {
        ttl: "Nice work!",
        txt: "<p>You are eligible to for Kraft Hockeyville's $10,000 Early Bird prize.</p>",
        btn1Txt: 'Go to My Community'
    },
    'earlyBirdReminder' : {
        ttl: "Congratulations!",
        txt: "<p>Your arena has qualified for Kraft Hockeyville 2012. You now have a chance to win $10,000 worth of equipment for your minor hockey association.</p>",
        btn1Txt: 'LEARN MORE'
    },
    'enteredEarly' : {
        ttl: "Sorry!",
        txt: "<p>You can only enter the Early Bird contest once.</p>",
        btn1Txt: 'Continue'
    },
    'joinCommunity' : {
        ttl: "Go team!",
        txt: "<p>Joining an arena's community page is a fun way to share your passion for hockey and team spirit.</p>",
        btn1Txt: 'Join Now!',
        btn2Txt: 'No Thanks'
    },
    
    /* Events */
    'newFBUser' : {
        ttl: "Thanks for connecting!",
        txt: "<p>Get in on the action to support your arena's quest to win!</p><h3>Share your passion for hockey!</h3><p>Tell your friends you are participating in Kraft Hockeyville 2012.</p>",
        btn1Txt: 'Share',
        btn2Txt: 'Continue'
    },
    'newEmailUser' : {
        ttl: "Thanks for signing up!",
        txt: "<p>Get in on the action to support your arena's quest to win!</p><h3>Join the game!</h3><p>Find and join an arena's community page to compete for the coveted Kraft Hockeyville title and prize.</p>",
        btn1Txt: 'Find a Community'
    },
    'joinedGroupFB' : {
        ttl: "Thanks for your support!",
        txt: "<p>You have joined <COMMUNITY_NAME></p><h3>Share your passion for hockey!</h3><p>Tell your friends you have joined our community's quest to become the next Kraft Hockeyville!</p><h3>Get busy and have fun!</h3><p>Upload content to support our quest to win! Participate in missions to earn trophies.</p>",
        btn1Txt: 'Share',
        btn2Txt: 'Continue'
    },
    'joinedGroupEmail' : {
        ttl: "Thanks for your support!",
        txt: "<p>You have joined <COMMUNITY_NAME></p><h3>Get busy and have fun!</h3><p>Upload content to support our quest to win! Participate in missions to earn trophies.</p><ul><li>Upload stories, images and videos</li><li>Participate in missions to earn trophies</li><li>Rate our community's submissions</li><li>Like, Share, Tweet and Invite Friends to promote our passion!</li></ul>",
        btn1Txt: 'Continue'
    },
    'requestGroup' : {
        ttl: "Your request has been received!",
        txt: "<p>Please allow up to 3 business days to process your request. If there are any issues with your request, we will contact you by email.</p>",
        btn1Txt: 'Continue'
    },
    'upload1NoteFB' : {
        ttl: "Please be patient!",
        txt: "<p>Your submission is being processed. It may take a few minutes before it appears in the gallery. </p><h3><span class='trophies trophy-0-real'></span>Congratulations!</h3><p>Your story submission has earned you the coveted Conception Bay South Cup, named in honour of the winner of Kraft Hockeyville 2011.</p><p class='post-trophy'>Thanks for supporting your community! Keep up the good work!</p><br/><p>Share your achievement and your passion for hockey with with friends!</p>",
        btn1Txt: 'Share',
        btn2Txt: 'Close'
    },
    'upload1NoteEmail' : {
        ttl: "Please be patient!",
        txt: "<p>Your submission is being processed. It may take a few minutes before it appears in the gallery. </p><h3><span class='trophies trophy-0-real'></span>Congratulations!</h3><p>Your story submission has earned you the coveted Conception Bay South Cup, named in honour of the winner of Kraft Hockeyville 2011.</p><p class='post-trophy'>Thanks for supporting your community! Keep up the good work!</p>",
        btn1Txt: 'Close'
    },
    'upload1PhotoFB' : {
        ttl: "Please be patient!",
        txt: "<p>Your submission is being processed. It may take a few minutes before it appears in the gallery. </p><h3><span class='trophies trophy-1-real'></span>Congratulations!</h3><p>Your image submission has earned you the coveted Dundas Trophy, named in honour of the winner of Kraft Hockeyville 2010.</p><p class='post-trophy'>Thanks for supporting your community! Keep up the good work!</p><br/><p>Share your achievement and your passion for hockey with with friends!</p>",
        btn1Txt: 'Share',
        btn2Txt: 'Close'
    },
    'upload1PhotoEmail' : {
        ttl: "Please be patient!",
        txt: "<p>Your submission is being processed. It may take a few minutes before it appears in the gallery. </p><h3><span class='trophies trophy-1-real'></span>Congratulations!</h3><p>Your image submission has earned you the coveted Dundas Trophy, named in honour of the winner of Kraft Hockeyville 2010.</p><p class='post-trophy'>Thanks for supporting your community! Keep up the good work!</p>",
        btn1Txt: 'Close'
    },
    'upload' : {
        ttl: "Thanks for supporting your community!",
        txt: "<p>Your submission is being processed. Please be patient! It may take a few minutes for it to appear on the site. We will contact you if there are any issues with your upload.</p>",
        btn1Txt: 'Close'
    },
    'msn2CompleteFB' : {
        ttl: "That's the spirit!",
        txt: "<h3><span class='trophies trophy-2-real'></span></h3><p>By adding your name to the Kraft Food for Families program, you have earned the Terrace Cup, named in honour of the Kraft Hockeyville 2009 winner.</p><br /><p class='post-trophy'>Share the spirit of giving and help Kraft help families!</p>",
        btn1Txt: 'Share',
        btn2Txt: 'Close'
    },
    'msn2CompleteEmail' : {
        ttl: "That's the spirit!",
        txt: "<h3><span class='trophies trophy-2-real'></span></h3><p>By adding your name to the Kraft Food for Families program, you have earned the Terrace Cup, named in honour of the Kraft Hockeyville 2009 winner.</p><br/><p class='post-trophy'>Thanks for helping Kraft help make the holidays easier for everyone.</p>",
        btn1Txt: 'Close'
    },
    'msn3CompleteFB' : {
        ttl: "Please be patient!",
        txt: "<p>Your submission is being processed. It may take a few minutes before it appears in the gallery.</p><h3><span class='trophies trophy-3-real'></span>Congratulations!</h3><p>Your submission has earned you the coveted Roberval Trophy, named in honour of the winner of Kraft Hockeyville 2008.</p><p class='post-trophy'>Thanks for supporting your community. Keep up the good work!</p><br/><p>Share your achievement and community spirit with friends!</p>",
        btn1Txt: 'Share',
        btn2Txt: 'Close'
    },
    'msn3CompleteEmail' : {
        ttl: "Please be patient!",
        txt: "<p>Your submission is being processed. It may take a few minutes before it appears in the gallery. </p><h3><span class='trophies trophy-4-real'></span>Congratulations!</h3><p>Your submission has earned you the coveted Mission 4 Trophy, named in honour of the winner of Kraft Hockeyville 200?.</p><br/><p class='post-trophy'>Keep up the good work!</p>",
        btn1Txt: 'Close'
    },
    'msn4CompleteFB' : {
        ttl: "Please be patient!",
        txt: "<p>Your submission is being processed. Stories and photos may take a few minutes and videos up to an hour before they appear in the gallery.</p><h3><span class='trophies trophy-4-real'></span>Congratulations!</h3><p>Your submission has earned you the coveted North Bay Cup, named in honour of the winner of Kraft Hockeyville 2007.</p><p class='post-trophy'>Share your achievement and bid to win with friends!</p>",
        btn1Txt: 'Share',
        btn2Txt: 'Close'
    },
    'msn4CompleteEmail' : {
        ttl: "Please be patient!",
        txt: "<p>Your submission is being processed. Stories and photos may take a few minutes and videos up to an hour before they appear in the gallery.</p><h3><span class='trophies trophy-4-real'></span>Congratulations!</h3><p>Your submission has earned you the coveted North Bay Cup, named in honour of the winner of Kraft Hockeyville 2007.</p><br/><p class='post-trophy'>Keep up the good work!</p>",
        btn1Txt: 'Close'
    },
    'msn5CompleteFB' : {
        ttl: "Please be patient!",
        txt: "<p>Your submission is being processed. Stories and photos may take a few minutes and videos up to an hour before they appear in the gallery.</p><h3><span class='trophies trophy-5-real'></span>Congratulations!</h3><p>Your submission has earned you the sought after Salmon River Trophy, named in honour of the winner of Kraft Hockeyville 2006.</p><p class='post-trophy'>Share your achievement and bid to win with friends!</p>",
        btn1Txt: 'Share',
        btn2Txt: 'Close'
    },
    'msn5CompleteEmail' : {
        ttl: "Please be patient!",
        txt: "<p>Your submission is being processed. Stories and photos may take a few minutes and videos up to an hour before they appear in the gallery.</p><h3><span class='trophies trophy-5-real'></span>Congratulations!</h3><p>Your submission has earned you the sought after Salmon River Trophy, named in honour of the winner of Kraft Hockeyville 2006.</p><br/><p class='post-trophy'>Keep up the good work!</p>",
        btn1Txt: 'Close'
    },
    'popupBanner1FB' : {
        ttl: "Welcome back Rookie!",
        txt: "<p>Congratulations! You have earned the Rookie status banner for your performance in Kraft Hockeyville 2012. Next level... Playmaker!</p><p>Share your achievement and passion for hockey with friends.</p>",
        btn1Txt: 'Share',
        btn2Txt: 'Close'
    },
    'popupBanner2FB' : {
        ttl: "You’re a Playmaker! Pass it on...",
        txt: "<p>Congratulations! You have earned the Playmaker status banner for your performance in Kraft Hockeyville 2012. Next level... Assistant Captain!</p><p>Share your achievement and passion for hockey with friends.</p>",
        btn1Txt: 'Share',
        btn2Txt: 'Close'
    },
    'popupBanner3FB' : {
        ttl: "An “A” for your efforts!",
        txt: "<p>Congratulations! You have earned the Assistant Captain status banner for your performance in Kraft Hockeyville 2012. Next level... All-Star!</p><p>Share your achievement and passion for hockey with friends.</p>",
        btn1Txt: 'Share',
        btn2Txt: 'Close'
    },
    'popupBanner4FB' : {
        ttl: "All-Star! What an honour...",
        txt: "<p>Congratulations! You have earned the All-Star status banner for your performance in Kraft Hockeyville 2012. Next level... Team Captain!</p><p>Share your achievement and passion for hockey with friends.</p>",
        btn1Txt: 'Share',
        btn2Txt: 'Close'
    },
    'popupBanner5FB' : {
        ttl: "Lead the way Team Captain!",
        txt: "<p>Congratulations! You have earned the Team Captain status banner for your performance in Kraft Hockeyville 2012. Next level... Leading Scorer!</p><p>Share your achievement and passion for hockey with friends.</p>",
        btn1Txt: 'Share',
        btn2Txt: 'Close'
    },
    'popupBanner6FB' : {
        ttl: "League leader!",
        txt: "<p>Congratulations! You have earned the Leading Scorer status banner for your impressive performance in Kraft Hockeyville 2012. Now you’re in contention for the ultimate honour, regional MVP!</p><p>Share your achievement and passion for hockey with friends.</p>",
        btn1Txt: 'Share',
        btn2Txt: 'Close'
    }
};

jQuery.validator.addMethod("phoneUS", function(phone_number, element) {
    phone_number = phone_number.replace(/\s+/g, ""); 
    return this.optional(element) || phone_number.length > 9 &&
        phone_number.match(/^(1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/);
}, "Please specify a valid phone number");

jQuery.fn.inputHints=function() {
   $(this).each(function(i) {
        $(this).val($(this).attr('title'))
    });

    return $(this).focus(function() {
        if ($(this).val() == $(this).attr('title'))
            $(this).val('')
    }).blur(function() {
        if ($(this).val() == '')
            $(this).val($(this).attr('title'))
    });
};


