﻿//Need to find a better place for these variables
var VotingID = '';
var VotingPH = '';
var VotingLogin = false;
var VotingOpen = false;

// NAMESPACES
var BenefulMap = {}; // Namespaces all functions in Beneful Map
BenefulMap.Constants = {};
BenefulMap.Constants.Snippets = {};
BenefulMap.Constants.Strings = {};
BenefulMap.Constants.Integers = {};


// CONSTANTS - ALL PAGES
BenefulMap.Constants.DETAILS_ZOOM = 14; // Used on the details page
BenefulMap.Constants.USA_ZOOM = 4;
BenefulMap.Constants.CITY_ZOOM = 10;
BenefulMap.Constants.WELCOME_MESSAGE_DURATION = 15000;

BenefulMap.Constants.SEARCH_KEYWORD_DEFAULT_VALUE = 'Search for spots';
BenefulMap.Constants.SEARCH_LOCATION_DEFAULT_VALUE = 'In (city, state or zip)';

BenefulMap.Constants.CENTER_LAT = "37.40";
BenefulMap.Constants.CENTER_LNG = "-95.50";
BenefulMap.Constants.CENTER_LATLNG = new GLatLng(BenefulMap.Constants.CENTER_LAT, BenefulMap.Constants.CENTER_LNG);

BenefulMap.Constants.IMG_MARKER = root + "_res/i/marker/marker_blank.png";
BenefulMap.Constants.IMG_ACTIVE_MARKER = root + "_res/i/marker/marker_active.png";
BenefulMap.Constants.IMG_LOADER = root + "_res/i/spinner.gif";

BenefulMap.Constants.Snippets.INFOWIN_BASICS = root + "Snippets/InfoWindow/Basics.aspx";
BenefulMap.Constants.Snippets.INFOWIN_SEND = root + "Snippets/InfoWindow/SendContent.aspx";
BenefulMap.Constants.Snippets.INFOWIN_PREVIEW = root + "RenderPhoto.aspx?id=%SPOT_ID%&context=spot&infowindow=y&maxHeight=78&maxWidth=100&subcontext=%CAT_NUM%";
BenefulMap.Constants.Snippets.MODAL_ADD_SPOT = root + "Snippets/AddSpot.aspx";
BenefulMap.Constants.Snippets.MODAL_EDIT_SPOT = root + "Snippets/EditSpot.aspx";
BenefulMap.Constants.Snippets.MODAL_LINK_RESULTS = root + "Snippets/LinkToResults.aspx";
BenefulMap.Constants.Snippets.MODAL_ADD_REVIEW = root + "Snippets/AddReview.aspx";
BenefulMap.Constants.Snippets.MODAL_VOTE_DREAMDOGPARK = root + "Snippets/DreamDogPark/Vote.aspx";
BenefulMap.Constants.Snippets.MODAL_TELL_FRIEND = root + "Snippets/TellFriend.aspx";
BenefulMap.Constants.Snippets.MODAL_LOGIN = root + "Snippets/LogUserIn.aspx";
BenefulMap.Constants.Snippets.MODAL_SEND_FEEDBACK = root + "Snippets/SendFeedback.aspx";
BenefulMap.Constants.Snippets.MODAL_REQUEST_REMOVAL = root + "Snippets/RequestRemoval.aspx";
BenefulMap.Constants.Snippets.MODAL_SEND_PHONE = root + "Snippets/SendToPhone.aspx";
BenefulMap.Constants.Snippets.MODAL_ADD_PHOTO = root + "Snippets/AddPhoto.aspx";
BenefulMap.Constants.Snippets.MODAL_SHARE_THIS = root + "Snippets/ShareThis.aspx";
BenefulMap.Constants.Snippets.PANE_PAGINATION = root + "Snippets/Paging.aspx";
BenefulMap.Constants.Snippets.PANE_RESULTS = root + "Snippets/Results.aspx";
BenefulMap.Constants.Snippets.PANE_NEARBY_SPOTS = root + "Snippets/NearbyPlaces.aspx";
BenefulMap.Constants.Snippets.TAB_REVIEWS = root + "Snippets/Reviews.aspx";
BenefulMap.Constants.Snippets.TAB_PHOTOS = root + "Snippets/Photos.aspx";
BenefulMap.Constants.Snippets_PAGE_SEARCH_RESULTS = root + "Find-Spots/Default.aspx?search=%LOC%&keyword=%KEY%&ref=%REF%";
BenefulMap.Constants.Snippets.MODAL_FULL_SIZE_PHOTO = root + "Snippets/FullSizePhoto.aspx";
BenefulMap.Constants.Snippets.MODAL_PROMOTION = root + "Snippets/Promotion/FreeDogToyThankYou.aspx";
BenefulMap.Constants.Snippets.MODAL_REGISTER = root + "Snippets/Register.aspx";
BenefulMap.Constants.Snippets.SUBMIT_POLL = root + "/Controls/InteractiveContent/PollSnippet.aspx?context=answers";
BenefulMap.Constants.Snippets.SUBMIT_OPEN_ANSWER = root + "/Controls/InteractiveContent/OpenEndedQuestionSnippet.aspx?context=answer";

BenefulMap.Constants.Strings.ADDRESS_FIELD_TEXT = 's';
BenefulMap.Constants.Strings.CATEGORY_FILTER_PREFIX = "category";
BenefulMap.Constants.Strings.PAGING_LINK_PREFIX = "page";
BenefulMap.Constants.Strings.RESULTS_ITEM_PREFIX = "spot";
BenefulMap.Constants.Strings.TOGGLE_SHOW = 'View All';
BenefulMap.Constants.Strings.TOGGLE_HIDE = 'Collapse';
BenefulMap.Constants.Strings.ADD_SPOT_HEADLINE = 'If you could describe this Spot in one sentence, what would you say?';
BenefulMap.Constants.Strings.ADD_SPOT_REVIEW = 'Tell us about the adventure you and your buddy had, and why you would recommend this Spot.';

BenefulMap.Constants.Integers.TRUNCATE_ARTICLE_CATEGORY_DESCRIPTION = 140;

// Extending global string object
String.prototype.startsWith = function(str) {
	return(this.match('^' + str) == str);
};

$(document).ready(function() {

    AjaxPro.timeoutPeriod = 20 * 1000; //increasing timeout period globally (had issues with log in 1/19/2011)

    BenefulMap.setupSearchBar();

    //BenefulMap.setupRegistrationModal();

    BenefulMap.openSSLRegistraion = function(link) {
        $(link).popup({
            scrollbars: true,
            windowname: 'WagWorldRegistration',
            resizable: false,
            status: false,
            width: 600,
            height: 660
        });
    }
    BenefulMap.openSSLRegistraion('a.register');


    BenefulMap.setupLoginModal();
    BenefulMap.setupForgotPasswordModal();

    BenefulMap.setupAddSpotModal();
    BenefulMap.setupAddReviewModal();
    BenefulMap.setupVoteDreamdogparkModal();
    BenefulMap.setupRequestRemovalModal();
    BenefulMap.setupTellFriendFooterModal();
    BenefulMap.setupSendFeedbackModal();
    BenefulMap.setupModalShareThisFooter();
    BenefulMap.setupNewWindows();
    BenefulMap.setupPopUps();
    BenefulMap.setupPromotionModal();
    BenefulMap.setupTellFriendToutModal();
    BenefulMap.setupToggleLists();
    BenefulMap.permitPostBack();

    BenefulMap.baseHref = $("AbsoluteRoot").val(); // expose absolute root URL from web.config

    // Enable tour button globally
    $('#search-tour').wagWorldTour({ siteRoot: root });
    //$('#search-dreamdogpark').wagWorldPromo({ siteRoot: root });

    //Enable cycle plug-in on homepage
    $('#tabs').cycle({
        pager: '#tab-nav',
        timeout: 8000
    });

    //Enable cycle plug-in for the Featured Spotlight module
    //Enabled on home page
    $('.featured-spotlights-home .spotlights-list').cycle({
        pager: '.featured-spotlights-home .spotlights-nav',
        timeout: 8000,
        prev: '.featured-spotlights-home .spotlights-nav-container a.prev',
        next: '.featured-spotlights-home .spotlights-nav-container a.next'
    });
    //Enabled on the left column in on Adventures page
    $('.first-col-1 .spotlights-list').cycle({
        pager: 'first-col-1 .spotlights-nav',
        timeout: 8000,
        prev: 'first-col-1 .spotlights-nav-container a.prev',
        next: 'first-col-1 .spotlights-nav-container a.next'
    });
    //Enabled on the middle column in on Adventures page
    $('.second-col-1 .spotlights-list').cycle({
        pager: 'second-col-1 .spotlights-nav',
        timeout: 8000,
        prev: 'second-col-1 .spotlights-nav-container a.prev',
        next: 'second-col-1 .spotlights-nav-container a.next'
    });


    //If there is more than one quiz or poll on the page, you must specify
    //the input fields selector with questionId
    $("#default-poll-module").wagWorldPoll({
        questionId: "#default-poll-module input.question-id"
    });

    $("#default-quiz-module").wagWorldQuiz({
        questionId: "#default-quiz-module input.question-id"
    });

    $("#DogLoversSaying").wagWorldComments();

    $("#article-comments").wagWorldComments({
        submitButton: "a.comment-submit",
        enabledButtonClass: "css-button-active",
        comment: ".comment-field textarea",
        errorField: ".comments-wrapper .submit-error",
        answerType: 0,
        questionId: "input.article-id",
        snippetPath: "Controls/Articles/CommentSnippet.aspx?context=answer",
        ajaxPane: ".comments-wrapper"
    });

    // Enable carousel plug-in on newest members
    $('.newest-members ul').jcarousel({ visible: 6 });

    // Enable carousel plug-in on What's Happening	
    $('#whats-happening-wrapper ul').jcarousel({ visible: 5 });

    // Enable carousel plug-in on Dream Dog Park
    $('#dreamdogpark-entry-gallery ul').jcarousel({ visible: 7 });

    // Enable carousel plug-in on Dream Dog Park
    $('#dreamdogpark-winner-2010-gallery ul').jcarousel({ visible: 5 });

    // What dog lovers are saying border fix
    $('#lover-reviews li:first-child').addClass('no-border');

    // Hover class backup
    BenefulMap.hoverBackup("div#search-bottom ul#lover-reviews li");

    //Load Large JS Content
    $(".ajax-loader").hide();
    $(".delay-load").css("visibility", "visible");

    BenefulMap.sfHover();
    BenefulMap.setupTruncateDescription();

    //Initiate showNav function
    Navigation.hoverEvent(Navigation.navElements);



});


//Set up Navigation namespace
var Navigation = {};
Navigation.navElements = $('#first-tier-nav li.primary-items'); //Grabs all of the elements with a class of .nav
Navigation.speed = 100; //Set global speed for animation and timeout
Navigation.timer; //Global timer for mouse enter
Navigation.openTimer; //Global timer for open nav
Navigation.currentNav;

//Controls mouse enter and mouse leave events for the Navigations, calls slide effect down and slide effect up
Navigation.hoverEvent = function(el) {
    if ($('body').hasClass('adventures')) {
        Navigation.currentNav = $('#adventures-nav');
    } else if ($('body').hasClass('dreamdogpark')) {
        Navigation.currentNav = $('#dreamdogpark-nav');
    } else if ($('body').hasClass('community')) {
        Navigation.currentNav = $('#community-nav');
    } else if ($('body').hasClass('find-spots')) {
        Navigation.currentNav = $('#find-spots-nav');
    }

    $(el).mouseenter(function() {
        clearTimeout(Navigation.timer);
        clearTimeout(Navigation.openTimer);
        Navigation.openClose(this);
    });
    $('.green-background, #content').mouseenter(function() {
        clearTimeout(Navigation.timer);
        clearTimeout(Navigation.openTimer);
        Navigation.openClose(Navigation.currentNav);
    });
};

//This function controls the opening and closing of the navigation
Navigation.openClose = function(el) {
    var sibs = Navigation.getSiblingNav(el);
    Navigation.timer = setTimeout(function() {
        if (Navigation.getSubNav(el).length > 0) {
            $.each(sibs, function() {
                $(this).hide();
            });
        }
        Navigation.openTimer = setTimeout(function() {
            if (Navigation.getSubNav(el).length <= 0) {
                $.each(Navigation.getSiblingNav(Navigation.currentNav), function() {
                    $(this).hide();
                });
                Navigation.getSubNav(Navigation.currentNav).show();
            } else {
                Navigation.getSubNav(el).show();
            }
        }, Navigation.speed);
    }, Navigation.speed);

};

//grabs the sub nav of the targeted element
Navigation.getSubNav = function(el) {
    var subNav = $(el).children('ul');
    return subNav;
};

//grabs the sub nav of the targeted element
Navigation.getSiblingNav = function(el) {
    var siblingNav = $(el).siblings().children('ul');
    return siblingNav;
};



BenefulMap.sfHover = function() {
    var sfEls = document.getElementById("first-tier-nav").getElementsByTagName("li");
    for (var i = 0; i < sfEls.length; i++) {
        sfEls[i].onmouseover = function() {
            this.className += " sfhover";
        };
        sfEls[i].onmouseout = function() {
            this.className = this.className.replace(new RegExp(" sfhover\\b"), "");
        };
    }
};

// Hover class backup
BenefulMap.hoverBackup = function(selector){
    if($(selector).length){
        var $items = $(selector);
        var cssClass = "hover";
        
        $items.mouseover(function(){
            $(this).addClass(cssClass);
        });
        
        $items.mouseout(function(){
            $(this).removeClass(cssClass);
        });
    }
};

BenefulMap.permitPostBack = function() {
	$(".post-back").keypress( function(event) {
		if (event.which == 13) {
			event.preventDefault();
			$(this).find("input:image, input:submit").click();
		}
	});
};

BenefulMap.setupPromotionModal = function() {
	var els = {
		modalDiv: "#modal-promotion",
		targetElement: "#modal-promotion-link"
	};
	var fields = {
		fieldsToSerialize: "#modal-promotion input:text, #modal-promotion select",
		fieldsToValidate: "#modal-promotion input:text, #modal-promotion select",
		requiredFields: "#modal-promotion input:text:not(.optional), #modal-promotion select",
		checkbox: "#modal-promotion input:checkbox"
	};
	// modalTitle, modalElements, modalOptions, snippetPath, params, formElements
	var promoModal = new BenefulMap.ModalToyPromotion("Thank You",  els, {}, BenefulMap.Constants.Snippets.MODAL_PROMOTION, {}, fields);
};

BenefulMap.setupSearchBar = function() {
    var searchBar = new BenefulMap.SearchBar("form", "#header #keyword-search", "#header #address-search", "#header #submit-search");
};

BenefulMap.setupLoginModal = function() {
    var loginEl = { 
		modalDiv: "#modal-login",
		targetElement: "a.login",
		forgotPasswordLink: "#forgot-password", 
		backToLoginLink: "a.backToLogin"
	};
	var loginFieldsEl = {
		fieldsToSerialize: "#modal-login input:text, #modal-login input:password, #modal-login input:checkbox",
		fieldsToValidate: "#modal-login input:text",
		requiredFields: "#modal-login input:text, #modal-login input:password"
	};
	var params = {
	    ph: 1
    };
	var loginModal = new BenefulMap.ModalLoginForm("Login", loginEl, {}, BenefulMap.Constants.Snippets.MODAL_LOGIN, params, loginFieldsEl);
};

BenefulMap.setupForgotPasswordModal = function() {
	var forgotPasswordEls = {
		modalDiv: "#modal-password",
		targetElement: "a.forgot-password",
		forgotPasswordLink: "#forgot-password", 
		backToLoginLink: "a.backToLogin"
	};
	var forgotPasswordFieldsEls = {
		fieldsToSerialize: "#modal-password input:text",
		fieldsToValidate: "#modal-password input:text",
		requiredFields: "#modal-password input:text"
	};
	var params = {
		ph: 2
	};
	var forgotPasswordModal = new BenefulMap.ModalForgotPasswordForm("Forgot Password?", forgotPasswordEls, {}, BenefulMap.Constants.Snippets.MODAL_LOGIN, params, forgotPasswordFieldsEls);
};

BenefulMap.setupRegistrationModal = function() {
    var el = {
        modalDiv: "#modal-registration",
        targetElement: "a.registter"
    };
    var fieldsEl = {
        fieldsToSerialize: "#modal-registration input:text, #modal-registration input:password, #modal-registration input:checkbox, #modal-registration input:radio",
        fieldsToValidate: "#modal-registration input:text",
        requiredFields: "#modal-registration input:text:not(.optional-field), #modal-registration input:checkbox, #modal-registration input:radio, #modal-registration input:password"
    };
    var params = {
        ph: 1
    };
    var regModal = new BenefulMap.ModalRegistrationForm("WagWorld Registration", el, { width: 544 }, BenefulMap.Constants.Snippets.MODAL_REGISTER, params, fieldsEl);
};

BenefulMap.setupAddSpotModal = function() {
	var els = {
		modalDiv: "#modal-add",
		targetElement: "#add-spot, #footer-add a, #no-results-add-spot-link, .add_to_ww, .widget_header_main .add_spot a"
	};
	var formEls = {
		fieldsToSerialize: "#modal-add input:text, #modal-add input:radio, input:checkbox, #modal-add select, #modal-add textarea",
		fieldsToValidate: "#modal-add input:text, #modal-add input:radio, #modal-add select, #modal-add textarea",
		requiredFields: "#modal-add input:text:not(.optional-field), #modal-add input:radio, #modal-add select, #modal-add textarea"
	};
	formEls.checkDuplicate = {};
	formEls.checkDuplicate.fieldsToSerialize = "#add-spot-check-duplicate input:text, #add-spot-check-duplicate select";
	formEls.checkDuplicate.fieldsToValidate = "#add-spot-check-duplicate input:text, #add-spot-check-duplicate select";
	formEls.checkDuplicate.requiredFields = "#add-spot-check-duplicate input:text:not(.optional-field), #add-spot-check-duplicate select";
	formEls.step1 = {};
	formEls.step1.fieldsToSerialize = "#add-spot-step-1 input:text, #add-spot-step-1 input:radio,  #add-spot-step-1 input:checkbox, #add-spot-step-1 select, #add-spot-step-1 textarea";
	formEls.step1.fieldsToValidate = "#add-spot-step-1 input:text, #add-spot-step-1 select, #add-spot-step-1 textarea";
	formEls.step1.requiredFields = "#add-spot-step-1 input:text:not(.optional-field), #add-spot-step-1 input:radio, #add-spot-step-1 select";
	formEls.step2 = {};
	formEls.step2.fieldsToSerialize = "#add-spot-step-2 input:text, #add-spot-step-2 input:radio, #add-spot-step-2 select, #add-spot-step-2 textarea";
	formEls.step2.fieldsToValidate = "";
	formEls.step2.requiredFields = "";
	
	var fieldsets = {
		checkDuplicate: "#add-spot-check-duplicate",
		duplicateSpots: "#add-spot-duplicate-spots",
		step1: "#add-spot-step-1",
		step2: "#add-spot-step-2",
		uploadPhoto: "#add-spot-upload-photo",
		thankYou: "#add-spot-thank-you"
	};
	
	var categoryFieldsets = {
		eat: "#add-spot-eat",
		play: "#add-spot-play",
		stay: "#add-spot-stay"
	};

	var categoryFieldsetsParameters = {
		selectedCategory: "li.spot-category",
		radioGroupSelector: ".radioGroup",
		checkboxGroupSelector: ".checkboxGroup",
		dropdownGroupSelector: ".addSpotCategoryDropdown",
		questionKey: "categoryQuestion",
		answerKey: "answer"
	};
	
	var addSpotFieldBehaviors = {
		titleDefaultText: "If you could describe this Spot in one sentence, what would you say?",
		reviewDefaultText: "Tell us about the adventure you and your buddy had, and why you would recommend this Spot.",
		titleSelector: "#Headline",
		reviewSelector: "#Review"
	};
	
	var links = {
		back: "a.add-spot-back",
		skip: "a.add-spot-skip"
	};
	var continueButtons = {
		checkDuplicate: "#add-spot-check-duplicate-button",
		duplicateSpots: "#add-spot-found-duplicate-button",
		step1: "#add-spot-step-1-button",
		step2: "#add-spot-step-2-button",
		uploadPhoto: "#add-spot-upload-photo-button",
		thankYou: ""
	};
	var initialParams = {
		ph: 1
	};
	var newModal = new BenefulMap.ModalAddSpot("Add a Spot", "add-spot", els, { width: 755 }, BenefulMap.Constants.Snippets.MODAL_ADD_SPOT, initialParams, formEls, fieldsets, links, continueButtons, ".spot-category input:radio", "#OtherCategorySuggestion",categoryFieldsets,categoryFieldsetsParameters,addSpotFieldBehaviors);
};

BenefulMap.setupTellFriendFooterModal = function() {
	var tellFriendEls = {
		modalDiv: "#modal-tell-friend-footer",
		targetElement: "#footer-invite a"
	};
	var formEls = {
		fieldsToSerialize: "#modal-tell-friend-footer input:text, #modal-tell-friend-footer textarea",
		fieldsToValidate: "#modal-tell-friend-footer input:text, #modal-tell-friend-footer textarea",
		requiredFields: "#modal-tell-friend-footer input:text"
	};
	var newModal = new BenefulMap.ModalTellFriend("Invite a Friend", tellFriendEls, {}, BenefulMap.Constants.Snippets.MODAL_TELL_FRIEND, {}, formEls, "site");
	
};

BenefulMap.setupToggleLists = function() {
	$('#truncate-spotlight').truncateList({ showCount: 5, targetContainer: '#spotlight' });
	$('.truncate-lover-reviews').truncateList({ showCount: 4, targetContainer: '#spot-reviews-container' });
	$('#truncate-community-thoughts').truncateList({ showCount: 3, targetContainer: '.thoughts-community' });
	$('.truncate-most-commented').truncateList({ showCount: 6, targetContainer: '.most-commented' });
	$('.truncate-open-question-list').truncateList({ showCount: 2, targetContainer: '.open-question-wrapper' });
	$('.truncate-comment-list').truncateList({ showCount: 3, targetContainer: '.comments-wrapper' });
};

BenefulMap.setupTruncateDescription = function() {
	$("body.articles #column-1 #article-short-description .short-descript p").truncate(BenefulMap.Constants.Integers.TRUNCATE_ARTICLE_CATEGORY_DESCRIPTION, {
        chars: /\s/,
        trail: ["&hellip;", "&hellip;"]
    });

	$("body.find-spots #article-short-description .short-descript p").truncate(50, {
        chars: /\s/,
        trail: ["&hellip;", "&hellip;"]
    });

    $(".no-ie body.hub .related-articles li p, .ie8 body.hub .related-articles li p").truncate(50, {
        chars: /\s/,
        trail: ["&hellip;", "&hellip;"]
    });

    $("body.articles #content-carousel p.description").truncate(150, {
        chars: /\s/,
        trail: ["&hellip;", "&hellip;"]
    });

    $("body.home #content-carousel .description").truncate(150, {
        chars: /\s/,
        trail: ["&hellip;", "&hellip;"]
    });

};

BenefulMap.setupSendFeedbackModal = function() {
	var els = { 
		modalDiv: "#modal-send-feedback",
		targetElement: "#footer-send a, a.modal-send"
	};
	var fieldEls = {
		fieldsToSerialize: "#modal-send-feedback input:text, #modal-send-feedback textarea",
		fieldsToValidate: "#modal-send-feedback input:text, #modal-send-feedback textarea",
		requiredFields: "#modal-send-feedback input:text, #modal-send-feedback textarea"
	};
	var initialParams = {
		ph: 1
	};
	var newModal = new BenefulMap.ModalSendFeedback("Send Feedback", els, {}, BenefulMap.Constants.Snippets.MODAL_SEND_FEEDBACK, initialParams, fieldEls);
};

BenefulMap.setupAddReviewModal = function() {
	var addReviewEl = {
		modalDiv: "#modal-add-review",
		targetElement: ".add-review, .add-review-btn"
	};
	formEls = {
		fieldsToSerialize: "#modal-add-review input:text, #modal-add-review textarea",
		fieldsToValidate: "#modal-add-review input:text, #modal-add-review textarea",
		requiredFields: "#modal-add-review input:text, #modal-add-review textarea"
	};
	params = {
		ph: 1
	};
	var newModal = new BenefulMap.ModalAddReview("Add Review", "add-review", addReviewEl, {}, BenefulMap.Constants.Snippets.MODAL_ADD_REVIEW, params, formEls);
};

BenefulMap.setupVoteDreamdogparkModal = function() {
    var voteDreamdogparkEl = {
        modalDiv: "#modal-vote-dreamdogpark",
        targetElement: ".vote-dreamdogpark"
    };
    formEls = {
        fieldsToSerialize: "#modal-add-review input:text, #modal-add-review textarea",
        fieldsToValidate: "#modal-add-review input:text, #modal-add-review textarea",
        requiredFields: "#modal-add-review input:text, #modal-add-review textarea"
    };
    var newModal = new BenefulMap.ModalVoteDreamdogpark("Confirm Your Vote", "vote-dreamdogpark", voteDreamdogparkEl, {}, BenefulMap.Constants.Snippets.MODAL_VOTE_DREAMDOGPARK, params, formEls);
};

BenefulMap.setupRequestRemovalModal = function() {
	var els = {
		modalDiv: "#modal-request-removal",
		targetElement: "#request-removal, .remove-review"
	};
	var formEls = {
	    fieldsToSerialize: "#modal-request-removal input:text, #modal-request-removal textarea",
	    fieldsToValidate: "#modal-request-removal input:text",
	    requiredFields: "#modal-request-removal input:text, #modal-request-removal textarea"
	};
	var initialParams = {
		ph: 1
	};
	var newModal = new BenefulMap.ModalRemoveSpot("Request Removal", els, {}, BenefulMap.Constants.Snippets.MODAL_REQUEST_REMOVAL, initialParams, formEls);
};

BenefulMap.setupTellFriendToutModal = function() {
    var tellFriendEls = {
        modalDiv: "#modal-tell-friend-footer",
        targetElement: "#tout-invite a"
    };
    var formEls = {
        fieldsToSerialize: "#modal-tell-friend-footer input:text, #modal-tell-friend-footer textarea",
        fieldsToValidate: "#modal-tell-friend-footer input:text, #modal-tell-friend-footer textarea",
        requiredFields: "#modal-tell-friend-footer input:text"
    };
    var newModal = new BenefulMap.ModalTellFriend("Invite a Friend", tellFriendEls, {}, BenefulMap.Constants.Snippets.MODAL_TELL_FRIEND, {}, formEls, "site");

};

BenefulMap.setupModalShareThisFooter = function() {
    var els = {
        modalDiv: "#modal-share-footer",
        targetElement: "#footer-share"
    };
    var newModal = new BenefulMap.ModalShareThis("Share WagWorld", els, {}, BenefulMap.Constants.Snippets.MODAL_SHARE_THIS, {}, "site");
};

BenefulMap.setupNewWindows = function(){
	$("a.new-tab").newWindow();
};

BenefulMap.setupPopUps = function(){
	$("a.pop-up").popup({
		scrollbars:			true,
		resizable:			true,
		status:				false,
		width:				640,
		height:				600
	});
};

BenefulMap.setupTrackingOnLinks = function() {
	$("a").live("click", function() {
		var params = $(this).attr("rev");
		// TODO add tracking function here
		console.log("Params: ", params);	
	});	
};

//Use this function to open any modal from a popup window
//Syntax from popup page window.opener.SSLOpenModals('login');
//Use this for SSL
var SSLOpenModals = function(modal) {
    $(document).trigger(modal + '.open');
    return modal;
}

//silences console commands in browsers without firebug
if (!window.console || !console.firebug) {
	var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
	"group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];

	window.console = {};
	for (var i = 0; i < names.length; ++i)
		window.console[names[i]] = function() {};
}

window.onerror = function() {
	return false;
};

