//image rollover
//swap img src from "imagename-off.gif" to "imagename-on.gif" - works for any image folder path
//usage: apply class="rollover" to anchor link

var animCarouselFlag = false;
function rollover() {
	$(".rollover").hover(
		function() {
			this.src = this.src.replace("_off.","_on.");
		},
		function() {
			this.src = this.src.replace("_on.","_off.");
		}
	);
/*
	$(".active").hover(
		function() {
			this.src = this.src.replace("_on.","_on.");
		},
		function() {
			this.src = this.src.replace("_on.","_on.");
		}
	);		
*/
}

/********* Start Map load *************************/

        function loadLocationMap() 
        {
         
         var locationMapPath = $("#locationMapPath").html();
         
	 locationMapPath = strTrim(locationMapPath);
	  if ((locationMapPath != null))
  	{
            $('div#show-map').html("<iframe src=\""+locationMapPath+"\" width=\"586\" height=\"260\" scrollbar=\"no\" marginwidth=\"0\" marginheight=\"0\" hspace=\"0\" align=\"middle\" frameborder=\"0\"></iframe>"); 
      	}
        }
        
        function loadMapDescription()
        {
        var locationMapDescription = $("#LocationMapDescription").html();
        
        $("div.items-map").html(locationMapDescription);
        }
/********* End Map ***************************/

/********* Start video load *************************/

        function loadSnippetvideo() 
        {
         var videoPathSnippet = $("#videoFileName").html();
	 videoPathSnippet = strTrim(videoPathSnippet);
	  if ((videoPathSnippet != null) && (videoPathSnippet != ""))
  	{
   //$('div#pe-video .innervideo').load($('#videoFileName').html());
   $('div#pe-video .innervideo').load(videoPathSnippet, function() {setTimeout('homepageVideo();', 50);});
   
       }
        }
/********* End video ***************************/


var animationTime = 3000;
var stayTime = 1000;
var counter = 1;
var maxCount = 0;
var highlightsCarliArray;

function startCarousel()
{
  stopHighlightsAmin(); 
   maxCount = 0;
   counter = 1;
   animCarouselFlag = true;
   $("#carouselTempImg").remove();
   
   loadHighights();
   
}


var parkFolderName = "DevonCiffs";

/******************** Carousel for Snippet Page starts here *************************/
function loadHighights()
{

  
  if (maxCount == 0)
  {
  
    $(".highlightsMainImageFrameTemp").html('');  
            
    var carouselHtml = $("#HighlightsCarousel #Carouselhtml").html();
    if (carouselHtml != null)
    {
      carouselHtml = strTrim(carouselHtml);
      //replacing temp classes to real required classes
      carouselHtml = carouselHtml.replace(/highlightsMainImageFrameTemp/gi, "highlightsMainImageFrame");
      $('div.highlightsMainImage').html(carouselHtml);

      highlightsCarliArray = $("#HighlightsCarousel").find("li a");
      maxCount = highlightsCarliArray.length;
      if($("#carouselTempImg").html() == null)
      {
        var temphtml = $("#HighlightsCarousel #Carouselhtml").html();
        $("#HighlightsCarousel #Carouselhtml").html(temphtml + "<div id=\"carouselTempImg\">test</div>");
      }
      $('div.highlightsMainImageFrameTemp').css('opacity', 0);
      
    }
     
  }
  
  counter = counter + 1;
  if ((counter > maxCount) && (maxCount > 0))
   { 
   
     counter = 1;
   }

   if((animCarouselFlag == true) && maxCount > 0)
   {
      
    var fileName= highlightsCarliArray[counter-1].href;   //getting the carousel image path    
    $('div.highlightsMainImageFrame').css('opacity', 0);    
    $('div.highlightsMainImage .highlightsMainImageFrame').css("background-image", "url('" + fileName + "')");
    $("#carouselTempImg").html("<img src=\"" + fileName + "\"  onload=\"carouselImgLoaded();\">");
   

  }
    
}

function carouselImgLoaded()
{ 
    $('div.highlightsMainImage .highlightsMainImageFrame').css("display", "block");;
    highlightsLoaded();
}

function highlightsLoaded()
{
  //$('div.heavenExperienceMsg').css('display','none');
  
        $('div.highlightsMainImageFrame').animate({
    opacity : 1.0
  }, animationTime, "linear", highlightsframeLoaded);
  
  //alert($('div.havenExperienceImage').html());
}

function highlightsframeLoaded()
{
  //Putting the framebg image to outer div
  //alert($('div.highlightsMainImage').html());
  //alert( $('div.highlightsMainImageFrame').css("opacity"));
  
  //$('div.heavenExperienceMsg').css('display','block');
  var framebgImage = $('div.highlightsMainImageFrame').css('background-image');
  $('div.highlightsMainImage').css('background-image',framebgImage);
 
        $('div.highlightsMainImageFrame').animate({
      opacity : 0.0
  }, stayTime, "linear", loadHighights);
}

function stopHighlightsAmin()
{
  $('div.highlightsMainImageFrame').stop();
  $('div.highlightsMainImage').stop();
  animCarouselFlag = false;
}

/******************** Carousel for Snippet Page ends here *************************/

//corner application
//adds styled corner round selected elements
function applyCorners(panelId) {
    //$("#header").corner("tr round 21px #FFFFFF");
    $('.pe-tab-panel,#pe-highlights, #pe-video').corner({
        tl: { radius: 0 }, tr: { radius: 0 }, bl: { radius: 13 }, br: { radius: 0 }, antiAlias: true
    });
    if (panelId != null) {
        $("#" + panelId + " .items-two-col .item").corner({
        tl: { radius: 0 }, tr: { radius: 8 }, bl: { radius: 0 }, br: { radius: 8 }, antiAlias: true
    });
    }
}

//main panel navigation & interaction
function mainPanelInteraction() {
    
	initPanel();
	//show main panel
	showPanel();

}

function applyDarkItemBg(panelId) {
    $("#main #" + panelId + " .items-two-col").each(function() {
        var index = 0;
        var parentCol = this;
        $(".item", this).each(function() {
            index = index + 1;
            var rem = index % 4;
            if (rem == 0 || rem == 1) {
                $(this).addClass("darkItem");
            }
        });
    });
}

function initPanel() {
	$("#right UL LI A").removeAttr("href");
	$("UL.nav LI A").removeAttr("href");
	$("DIV.main-panel").hide();
	$("DIV.main-panel:first").show();
	$("#right UL LI:first").addClass("active");
	$(".items-map .item:first").css({
		"border-bottom" : "1px solid #636363",
		"margin-bottom" : "0.5em"
	});
}

function showPanel() {

    $("#right UL LI A").click(function() {
        var prevElemId = $("#right UL LI.active A").attr("id");
        var elemID = this.id;
        //		alert(elemID);


        var prevElemId = $("#right UL LI.active A").attr("id");
        var elemID = this.id;

        if (elemID != "video") {
            try {
                pauseVideo();
            }
            catch (e) {
            }
        }

        if (elemID != "highlights") {
            stopHighlightsAmin()
        }

        if (elemID == "video") {
            loadSnippetvideo();

            /******************Script functions for loading the js dynamically , added 26/10/2010 starts here****************/

            var script_video_js = document.createElement("script");
            script_video_js.src = "/js/Home_Video_Page_2011.js";
            script_video_js.type = "text/javascript";

            script_video_js.onreadystatechange = function() {
                if (this.readyState == 'complete') galJSLoaded();
            }
            script_video_js.onload = galJSLoaded;
            document.getElementsByTagName("head")[0].appendChild(script_video_js);

            /******************Script functions for loading the js dynamically , added 26/10/2010 ends here****************/
        }

        else if (this.id == "map") {
            loadLocationMap();
        }

        else if (this.id == "highlights") {
            startCarousel();
        }



        // hide active nav item and activate selected nav item
        $("#right UL LI").removeClass("active");
        $("A#" + elemID).parent("LI").addClass("active");
        // hide all banners and show selected banner
        //$("#main DIV.main-panel").hide();


        slidePanel(elemID, prevElemId);
        applyCorners("pe-" + elemID);
    });
}

function slidePanel(panelId, prePanelId) {
    if (panelId == prePanelId) {
        return;  //active panel clicked
    }
    track_Park(getPanelTrackName(panelId), null);
    //activating required tab on the panel  (last tab i.e. first in the sequence)
    $("#main DIV#pe-" + panelId).css("z-index", "10");
    var defaultID = $("#pe-" + panelId + " > UL LI A:first").attr("id");  //first tab anchor Id on the panel
    //$("DIV.pe-tab-panel").hide();
    $("DIV#pe-" + defaultID).show();   //showing first tab in the panel
    $("DIV#pe-" + defaultID).css("z-index", "12");
    $("A#" + defaultID).parent("LI").addClass("active").siblings().removeClass("active"); ;  //activating first tab in the panel
    //registering events for the tab click on the panel

    applyDarkItemBg("#pe-" + panelId);
    $("#main DIV#pe-" + panelId + " > UL.nav LI A").click(function() {
        var prevNavId = $("#main DIV#pe-" + panelId + " > UL.nav LI.active A").attr("id");

        //alert("Click function");
        var navID = this.id;
        var tabTitle = $(this).attr("title");
        $("UL.nav LI").removeClass("active");
        $("A#" + navID).parent("LI").addClass("active");
        slideTab(navID, prevNavId, tabTitle, panelId);
        //$("DIV.pe-tab-panel").hide();
        //$("DIV#pe-" + navID).fadeIn();   //showing clicked tab in the panel
    });

    $("#main DIV#pe-" + panelId).css("top", "396px").css("position", "absolute");

  
    $("#main DIV#pe-" + panelId).show(1, function() {
        $("#main DIV#pe-" + panelId).animate({ top: '0px' }, 'slow', function() {
            //alert("Hiding : " + "#main DIV#pe-" + prePanelId);
            $("#main DIV#pe-" + prePanelId).hide().css("z-index", "8");
         
            if (prePanelId == 'video') {
                $(".innervideo").html('');
            }
            $(this).css("position", "relative").css("z-index", "9");
        });
    });
   // $("#main DIV#pe-" + panelId).show();

}


function slideTab(tabId, prevTabId, tabTitle, panelId) {
    if (tabId == prevTabId) {
        return;  //active tab clicked 
    }
    track_Park(getPanelTrackName(panelId), tabTitle);
    $("DIV#pe-" + tabId).css("z-index", "13");
    $("DIV#pe-" + tabId).css("left", "724px").animate({ left: '0px' }, 'slow', function() {
        //alert("Hiding : " + "#main DIV#pe-" + prePanelId);
        $("DIV#pe-" + prevTabId).css("z-index", "11");
        $(this).css("z-index", "12");
    });
  //  $("#main DIV#pe-" + panelId).show();
}



//video player
//usage: any banner section containing video
//function params:
//				layerID = id of element to use as video player (usually an anchor tag <a>)
//				progressColor = progress bar (of 'played' video) color 
//				bufferColor = progress bar background/buffer color
//				buttonColor = player button color
//				buttonOverColor = player button hover color
//examples:
//				flowPlayer("video", "02A9BE", "81D4DF", "0059A2", "81D4DF");
function flowPlayer(layerID, progressColor, bufferColor, buttonColor, buttonOverColor) {
	flowplayer(layerID, "flowplayer/flowplayer-3.0.7.swf", { 
	    plugins: { 
		   controls: { 
		        // location of the plugin 
		        url: "flowplayer.controls-3.0.4.swf", 
		        // display properties such as size, location and opacity 
				width: 718,
				height: 32,
		        left: 0, 
		        top: 229,  
		        opacity: 0.7,  
		        // controlbar colors
		        backgroundGradient: 'none', 
				autoHide: "always",
		        timeColor: "#FFFFFF", 
				durationColor: "#ffffff",
				bufferGradient: "none",
				sliderColor: "#000000",
				sliderGradient: "none",
				volumeSliderColor: "#000000",
				volumeSliderGradient: "none",
				progressGradient: "none",
				timeBgColor: "#555555",
				//branded content
//		        background: "url(images/flowplayer-gradient.gif) top left repeat-x",
				progressColor: "#" + progressColor +"",
				bufferColor: "#" + bufferColor +"",
				buttonColor: "#" + buttonColor +"",
				buttonOverColor: "#" + buttonOverColor +"",
				//buttons
		        all: false, 
		        play: true, 
				stop: false,
				time: true,
		        scrubber: true, 
		        // tooltips
		        tooltips: { 
		            buttons: true
		        } 
		    } 
	    }
	});
	setTimeout('$("#video-loading").hide();', 2000);
	setTimeout('$("#load-video").show();', 2000);
}




/******************Script functions for loading the js dynamically , added 26/10/2010 starts here****************/

                var jsLoaded = 0;
                var cssLoaded = 0;
                var htmlLoaded = 0;
                var defaultCat = '';
                function galJSLoaded() {
                //alert("galJSLoaded");

                    jsLoaded = 1;
                    if (jsLoaded == 1 && cssLoaded == 1 && htmlLoaded == 1) {

                        initializegallery(defaultCat);
                    }
                }

                function galCSSLoaded() {
                //alert("galCSSLoaded");

                    cssLoaded = 1;
                    if (jsLoaded == 1 && cssLoaded == 1 && htmlLoaded == 1) {

                        initializegallery(defaultCat);
                    }
                }

                function galHTMLLoaded() {
                //alert("galHTMLLoaded");
                    $(".galleryOuter .navSection .sliderBase .imgSlider").slider();
                    htmlLoaded = 1;
                   /*var category=$('#hdnImageGalleryText').val();
                    LoadGallery(category);*/
                    //alert("htmlLoaded :"+htmlLoaded);
                    //alert("cssLoaded :"+cssLoaded);
                    //alert("jsLoaded :"+jsLoaded);
                  if (jsLoaded == 1 && cssLoaded == 1 && htmlLoaded == 1) {
			 //alert("initializegallery");
			 
                        initializegallery(defaultCat);
                    }           
                }                

         

/******************Script functions for loading the js dynamically , added 26/10/2010 ends here****************/

                function setNavHeights() {
                    $("#main .main-panel .nav li:nth-child(1)").css("margin", "0px");
                    $("#main .main-panel .nav li").each(function(liIndex, liElement) {
                        jQuery('<img />').load(
                            function() {
                               $(liElement).css("height", this.height + "px");
                               $("a", liElement).css("height", this.height + "px");
                            }
                        ).attr('src', $("DIV IMG", liElement).attr("src"));

                    });
                }





                function getOriginalHeightOfImg(imageSrc) {
                    var t = new Image();
                    t.src = imageSrc;
                    return t.width;
                }




                function track_Park(panelName, tabName) {
                    var currentpath = window.location.pathname;
                    var trackString = '';
                    if(tabName == null || tabName == '')
                    {
                       trackString = "|?desc=ParkSnippet&action=" + strTrim(panelName) + "&Tab=RHS";
                    }
                    else {
                        trackString = "|?desc=ParkSnippet&action=" + strTrim(panelName) + "_" + tabName.replace(/\s/g, "").replace("'", "\'") + "&Tab=LHS";
                    }
                    WEBABACUS.logclientdata('0', currentpath + trackString);
                    //alert(currentpath + trackString);              
                }
	
	
	
	function strTrim(strToTrim)
    {
        if (strToTrim != null && strToTrim != "")
        {
         strToTrim = strToTrim.replace(/^\s*/, "").replace(/\s*$/, "");  
        }
        return strToTrim;
    }

    function getPanelTrackName(panelId) {
        var panelTrackName = "";


        if (panelId == "video") {
            panelTrackName = "ViewVideo";
        }

        else if (panelId == "map") {
            panelTrackName = "locationmap";
        }

        else if (panelId == "highlights") {
            panelTrackName = "ParkHighlights";
        }

        else if (panelId == "activities") {
            panelTrackName = "Activities";
        }

        else if (panelId == "ents") {
            panelTrackName = "Entertainment";
        }

        else if (panelId == "shops") {
            panelTrackName = "ShopsAndService";
        }

        if (panelId == "offpark") {
            panelTrackName = "OffThePark";
        }

        else if (panelId == "new") {
            panelTrackName = "WhatsNew";
        }
        
        else if (panelId == "info") {
            panelTrackName = "UsefulInfo";
        }

        return panelTrackName;
    }
