// JavaScript Document
//Set the s.prop for advertisers on information page
function track_advertisers(advertiser) {
	s=s_gi(s_account);
	s.linkTrackVars = "prop29";
	s.prop29 = advertiser;
	s.tl(this,'o',"Advertiser");
}

// will add target to external links
function externalLinks() {
	if (!document.getElementsByTagName){
		return;
	}
	var anchors = document.getElementsByTagName("a"); 
	for (var i=0; i<anchors.length; i++) { 
		var anchor = anchors[i]; 
		if (anchor.getAttribute("href") &&  anchor.getAttribute("rel") == "external"){
			anchor.target = "_blank"; 
		}
	}
} 
window.onload = externalLinks;

function setUpTabs(){
	$('#media-tabs a').click(function(){
		var activetab = $(this).attr('href');
		$(this).parent().siblings().children('a').removeClass('active');
		$(this).addClass('active');
		$('#media .content-container').hide();
		$('#'+activetab).show();
		return false;
	});
	$('#content-tabs a').click(function(){
		var activetab = $(this).attr('href');
		$(this).parent().siblings().children('a').removeClass('active');
		$(this).addClass('active');
		$('#details-content .content-container').hide();
		$('#'+activetab).show();
		if(activetab == "directions"){
			loadmap(); // calls the map load function
		}
		return false;
	});
}
			
$(document).ready(function(){
			
   $('a').each(function () {
	var mylink = $(this).attr("href");
     if(typeof(mylink) != "undefined" && mylink.indexOf('compasscove.com') > 0){
		if(mylink.indexOf('?') > 0){
			$(this).attr("href",$(this).attr("href")+"&cmpid=CConMBH");
		}
		else {
			$(this).attr("href","http://www.compasscove.com/?cmpid=CConMBH");
		}
	 }
	 else if (typeof(mylink) != "undefined" && mylink.indexOf('bayviewresort.com') > 0){
		if(mylink.indexOf('?') > 0){
			$(this).attr("href",$(this).attr("href")+"&cmpid=BVonMBH");
		}
		else {
			$(this).attr("href","http://www.bayviewresort.com/?cmpid=BVonMBH");
		}
	 }
	 else if (typeof(mylink) != "undefined" && mylink.indexOf('dunesvillage.com') > 0){
		if(mylink.indexOf('?') > 0){
			$(this).attr("href",$(this).attr("href")+"&cmpid=DVonMBH");
		}
		else {
			$(this).attr("href","http://www.dunesvillage.com/?cmpid=DVonMBH");
		}
	 }
	  else if (typeof(mylink) != "undefined" && mylink.indexOf('caribbeanresort.com') > 0){
		if(mylink.indexOf('?') > 0){
			$(this).attr("href",$(this).attr("href")+"&cmpid=CBonMBH");
		}
		else {
			$(this).attr("href","http://www.caribbeanresort.com/?cmpid=CBonMBH");
		}
	 }
	 else if (typeof(mylink) != "undefined" && mylink.indexOf('longbayresort.com') > 0){
		if(mylink.indexOf('?') > 0){
			$(this).attr("href",$(this).attr("href")+"&cmpid=LBonMBH");
		}
		else {
			$(this).attr("href","http://www.longbayresort.com/?cmpid=LBonMBH");
		}
	 }
	  else if (typeof(mylink) != "undefined" && mylink.indexOf('oceanreefmyrtlebeach.com') > 0){
		if(mylink.indexOf('?') > 0){
			$(this).attr("href",$(this).attr("href")+"&cmpid=ORonMBH");
		}
		else {
			$(this).attr("href","http://www.oceanreefmyrtlebeach.com/?cmpid=ORonMBH");
		}
	 }
	 else if (typeof(mylink) != "undefined" && mylink.indexOf('breakers.com') > 0){
		if(mylink.indexOf('?') > 0){
			$(this).attr("href",$(this).attr("href")+"&cmpid=BRonMBH");
		}
		else {
			$(this).attr("href","http://www.breakers.com/?cmpid=BRonMBH");
		}
	 }
	  else if (typeof(mylink) != "undefined" && mylink.indexOf('litchfieldbeach.com') > 0){
		if(mylink.indexOf('?') > 0){
			$(this).attr("href",$(this).attr("href")+"&cmpid=LRonMBH");
		}
		else {
			$(this).attr("href","http://www.litchfieldbeach.com/?cmpid=LRonMBH");
		}
	 }
	 else if (typeof(mylink) != "undefined" && mylink.indexOf('montereybaysuites.com') > 0){
		if(mylink.indexOf('?') > 0){
			$(this).attr("href",$(this).attr("href")+"&cmpid=MBonMBH");
		}
		else {
			$(this).attr("href","http://www.montereybaysuites.com/?cmpid=MBonMBH");
		}
	 }
	 else if (typeof(mylink) != "undefined" && mylink.indexOf('driftwoodlodge.com') > 0){
		if(mylink.indexOf('?') > 0){
			$(this).attr("href",$(this).attr("href")+"&cmpid=DLonMBH");
		}
		else {
			$(this).attr("href","http://www.driftwoodlodge.com/?cmpid=DLonMBH");
		}
	 }
	 else if (typeof(mylink) != "undefined" && mylink.indexOf('paradiseresortmb.com') > 0){
		if(mylink.indexOf('?') > 0){
			$(this).attr("href",$(this).attr("href")+"&cmpid=PRonMBH");
		}
		else {
			$(this).attr("href","http://www.paradiseresortmb.com/?cmpid=PRonMBH");
		}
	 }
	 else if (typeof(mylink) != "undefined" && mylink.indexOf('northbeachrentals.com') > 0){
		if(mylink.indexOf('?') > 0){
			$(this).attr("href",$(this).attr("href")+"&cmpid=NBonMBH");
		}
		else {
			$(this).attr("href","http://www.northbeachrentals.com/?cmpid=NBonMBH");
		}
	 }
	});
   
   //Do the ranking system here
   $(".Ratingwrapper").each(function(i) {
            var explanationDiv = $(this).find(".explanation");
            var explanationText = $(this).find(".explanationText");
            var hdnField = $(this).find(".explanation >input:hidden");
            var ratingLabel = $(this).find(".ratingLabel");
            var ratingCap = $(this).find(".rating");

            //Hide the radio button labels since we don't need because javascript is enabled
            ratingLabel.hide();

            //Show the rating label we do need.
            ratingCap.show();

            //Hide the explanation section since javascipt is enabled
            explanationDiv.hide();

            //Turn the radio buttons into our stars
            $(this).find(".question").stars({
                captionEl: $(this).find(".caption")
            });

            $(this).find(".question").click(function() {
                var instance = $(this).data("stars");
                $(this).find(".caption");
                hdnField.val(instance.options.value);

                if (instance.options.value == 1 || instance.options.value == 2 || instance.options.value == 3 || instance.options.value == 4) {
                    explanationDiv.show();
                    if (explanationText.val() == "NA") {
                        explanationText.val('').focus();
                    }
                    else {
                        explanationText.focus();
                    }
                }
                else {
                    explanationDiv.hide();
                    explanationText.val("NA");
                }
            });
        });
 });

