/* Manu - Following 2 functions are for dynamic height of iframe modal */
function adjustIframeModalHeight(el){
    if ( $(".modalWindow").length > 0 || $(".modalDialog").length > 0 ){
        var height = $("body").height();
        window.parent.setIframeModalHeight( el, height );
        
        height = $("body").height();
        window.parent.setIframeModalHeight( el, height );
    }
}
function setIframeModalHeight(el, height){
    $(el).height(height);
}

//To increase or decrease the height to iframe as per needed.
function autoAdjustIframeModalHeight(){
    if ( $(".modalWindow").length > 0 || $(".modalDialog").length > 0 ){
		var height = $("body").height();
		try { window.parent.setAllIframeModalHeight( height ); } catch (e){}
		
        $(window).load(function(){
            var height = $("body").height();
            try { window.parent.setAllIframeModalHeight( height ); } catch (e){}
        });
    }
}
function setAllIframeModalHeight(height){
    $("body > .ui-dialog > .ui-dialog-content:visible").each(function(){
        if ( !$(this).find("iframe").hasClass("modalNoResize") ){
            $(this).height(height);
            if ( $(this).find("iframe").length > 0 ){
                $(this).find("iframe").height(height);
            }
        }
    });
    
    //Code to increase height of overlay window to set it's background color       //according to height of modal window. Fixed artf1006628.
    if($('.ui-widget-overlay').length > 0)
    {   
        var height = getDocHeight();
        $('.ui-widget-overlay').css('height',height);
    } 
}

//Function created to get maximum document height. Fixed artf1006628.
function getDocHeight() {
    var D = document;
    return Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    );
}

function closeModalWindow( sel ){
    if ( window.parent == window ){
        try {
            $( sel ).dialog( 'close' );
        } catch (e) {}
    } else {
        try {
            window.parent.$( sel ).dialog( 'close' );
        } catch (e) {}
    }
}

function closeAllModalWindows(){
    $("body > .ui-dialog > .ui-dialog-content").each(function(){
        $(this).dialog("close");
    });
}

function pageRefresh(){
    document.location.href = document.location.href;
}
	  


/**
* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne <brian@cherne.net>
*/
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:100};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);

// Manu - Extending the jQuery Datepicker class to fix "artf992072" && "artf992300"
$.extend(jQuery.datepicker, {
    _checkOffset: function(inst, offset, isFixed) {
	    var dpWidth = inst.dpDiv.outerWidth();
	    var dpHeight = inst.dpDiv.outerHeight();
	    var inputWidth = inst.input ? inst.input.outerWidth() : 0;
	    var inputHeight = inst.input ? inst.input.outerHeight() : 0;
	    var viewWidth = (window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth) + $(document).scrollLeft();
	    var viewHeight = (window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight) + $(document).scrollTop();

	    offset.left -= (this._get(inst, 'isRTL') ? (dpWidth - inputWidth) : 0);
	    offset.left -= (isFixed && offset.left == inst.input.offset().left) ? $(document).scrollLeft() : 0;
	    offset.top -= (isFixed && offset.top == (inst.input.offset().top + inputHeight)) ? $(document).scrollTop() : 0;

	    // now check if datepicker is showing outside window viewport - move to a better place if so.
	    offset.left -= (offset.left + dpWidth > viewWidth && viewWidth > dpWidth) ? Math.abs(offset.left + dpWidth - viewWidth) : 0;
	    offset.top -= (offset.top + dpHeight > viewHeight && viewHeight > dpHeight) ? Math.abs(offset.top + dpHeight + inputHeight*2 - viewHeight) : 0;

        // Manu - Manually override the vertical position to always pin the layer below the textbox
	    if ( offset.top < inst.input.offset().top + inputHeight ){
            offset.top = inst.input.offset().top - dpHeight;
        }
        
        if (offset.left + dpWidth >= viewWidth - 20) {
            offset.left = viewWidth - dpWidth - 30;
        }
	    return offset;
    }
});

function blankIframeFix(me){
    $(me).addClass("temp").removeClass("temp");
}


$(document).ready(function(){

/* Copied from snow.com DOM Ready
=========================================================================================== */
 /* image flicker fix: mister-pixel */ 
 if($.browser.msie && $.browser.version == '6.0'){
  try { 
   document.execCommand("BackgroundImageCache", false, true); 
  } catch(err) {}
}

// This code checks if session got timed out during the ajax calls. If session is expired then
// user is redirected to the error page.
$("body").ajaxComplete(function(event, request, settings) {
    if (request.responseText != null && request.responseText != undefined && request.responseText != "") {
        try {
            var result = eval('(' + request.responseText + ')');
            if (result != null && result.Message != undefined) {
                if (result.Message.toUpperCase() == 'SESSION_ERROR'.toUpperCase()) {
                    //top.location.href = "/Vailresorts/sites/global/ErrorPage.aspx?errid=SESSION_ERROR";
                }
            }
        }
        catch (e) {
            // This catch block is to absorb the exception during eval() function call.
        }
    }
});

$.ajaxSetup({
    timeout: 120000
});

    $(document).bind("keypress", function(evt){
        if (evt.keyCode == 13) {
            if( $(this).is("input[type='text']") )
                return false;
        }
    });

$("#middleTabsContainer ul.middleTabs a").bind("mouseup", function(e){
	var url = window.location.href;
    var arrHref = $(this).attr("href").split("#");
    if ( arrHref.length > 1 && arrHref[1].length > 0 ){
        window.location.replace(url.split("#")[0] + "#" + arrHref[1] + "#Top");
    }
});
$(window).load(function(){
	$("div#middleTabsContainer > ul.middleTabs > li.tabs-selected > a").triggerHandler('click');
});
if( $('#topNav ul').length > 0){
    $('#topNav ul').bgiframe(); // This will prevent z-index problems with the top menu in IE6 
}

if ( $(".modalWindow, .modalDialog").length > 0 ){
    autoAdjustIframeModalHeight();
}

/** Predictive Text Search Fixes - Start **/
if (typeof VAIL != "undefined" && $("input.searchHeaderHeav").length > 0){  
    $("input.searchHeaderHeav").predictiveText({
  	    data: VAIL.data.autocompleteList,
	    trigger:  function(){
	        if ( search_btnSubmit_onclick ){
	            search_btnSubmit_onclick();
	        }
	    },
	    onEnter: function(){
	    if($('[id$=txtSearchText]').length > 0)
	        {
	            var txtSearch = $('[id$=txtSearchText]').val();
                if (txtSearch.toLowerCase() == "search" || $.trim(txtSearch) == '') {
                    return false;
                }
            }
            
	        //var searchurl = document.location.href;
//	        var searchTerm = $('[id$=txtSearchText]').val();//$('.searchHeaderHeav').val();
//	        if( $("[id$='hdnSearchPage']").length > 0 && $.trim( $("[id$='hdnSearchPage']").eq(0).val() ).length > 0 ) {
//                window.location.href = $("[id$='hdnSearchPage']").eq(0).val() + '?searchTerm='+searchTerm+'&page=1&SearchType=AllResults';
//            }
            /*	        
	        var searchIndex = self.location.protocol + '//' + self.location.host;// + self.location.pathname;// searchurl.indexOf('?');
	        if(searchurl.indexOf('?') == '-1')
            {                        
                //searchurl = searchIndex + '?searchTerm='+searchTerm+'&page=1&SearchType=AllResults';                           
                searchurl = searchIndex + '/Search/Keyword-Search.aspx?searchTerm='+searchTerm+'&page=1&SearchType=AllResults';                           
            }
            else
            {               
                searchurl = searchIndex + '/Search/Keyword-Search.aspx?searchTerm='+searchTerm+'&page=1&SearchType=AllResults';                              
            }            
            window.location = searchurl;
            //location.reload();*/
	        

	    }
    });
}
/** Predictive Text Search Fixes - Ends **/

//code for adding 'class' on instructor profile page
if ( $('.profileDataOther').length ) $('.profileDataOther ul:first-child').addClass('first')

/*Begin:Kuldip:Footer Fix Ie6 pseudoclass issue*/
$('#footer ul > li.first:first').addClass('firstChild');
/*End:Footer Fix Ie6 pseudoclass issue*/

// Init plan trip Go and Close buttons
	$(".planYourVacationContainer .closeBtn").click(function(){
		$(this).closest(".planYourVacationContainer").addClass("hidden");
	})
	$(".#panningPanel .go").click(function(){
		$(".planYourVacationContainer").removeClass("hidden")
	})


//$("#middleTabsContainer ul.middleTabs a").bind("click", function(e){
//    document.location.href = document.location.href.split("#")[0] + $(this).attr("href");    
//});

$(".contentContainer").each(function(){
  var index = $(".contentContainer").index(this);
  if(index == 1 ){
	$(this).addClass("topDivider");
  };
  if(index == 2 ){
	$(this).addClass("shadeMode");
  };
   if(index == 3 ){
	$(this).addClass("shadeMode");
  };

})

$(".signUp input").focus(function(){
	if ($(this).attr("value")=="YOUR EMAIL ADDRESS"){
		$(this).attr("value","")
	}
}).blur(function(){
	if ($(this).attr("value")==""){
		$(this).attr("value","YOUR EMAIL ADDRESS")
	}
})
$("#accountInfoTopBar input").focus(function(){
	if ($(this).attr("value")=="SEARCH THE SITE"){
		$(this).attr("value","")
	}
}).blur(function(){
	if ($(this).attr("value")==""){
		$(this).attr("value","SEARCH THE SITE")
	}
})

//$("#middleTabsContainer ul.middleTabs a").live("mousedown", function(e){
//    document.location.href = document.location.href.split("#")[0] + $(this).attr("href");    
//});


 function mycarousel_itemFirstInCallback(carousel, item, idx, state) {}; 

// functions need to be set on DOM load (first time) [begin]
	//setSelectedThumbnail();
// functions need to be set on DOM load (first time) [end]

function mycarousel_initCallback(carousel) {
	
		carousel.options.scroll = jQuery.jcarousel.intval(3);
	$(".hmPagination").text("");		
			var noLi = $('#hmCarousel li').length;
			var requiredLi = Math.ceil(noLi/3);
			for (var i=0; i<requiredLi; i++){
				var count = i+1;
			var liSrting ="<li>" +count+ "</li>";
				$(".hmPagination").append(liSrting);
			}
			$(".hmPagination").children(":first").addClass("selected");
			$(".jcarousel-next").click(function(){
				$(".hmPagination").find("li.selected").next().addClass("selected");
				$(".hmPagination").find("li.selected:last").prev().removeClass("selected");
			})
			$(".jcarousel-prev").click(function(){
				$(".hmPagination").find("li.selected:last").prev().addClass("selected");
				$(".hmPagination li.selected").next().removeClass("selected")
				})
			
			$('.hmPagination li').each(function(){
				
				$(this).bind("click",function() {
					$('.hmPagination li').removeClass("selected");
					$(this).addClass("selected");
					var noClick =parseInt($(this).text());
					var remain = noLi%3;
					if ($(this).text()=="1"){
						carousel.scroll(jQuery.jcarousel.intval(1))
					}
					if (remain==0){
						var ulLi= $("ul.pagination li").length
						var scrollNo = ((noClick-1)*3)+1
						carousel.scroll(jQuery.jcarousel.intval(scrollNo))
					}else{
						var scrollNo = ((noClick-1)*3)+1
						carousel.scroll(jQuery.jcarousel.intval(scrollNo))
					}			
						//carousel.scroll(jQuery.jcarousel.intval(firstItem));
						// return false;
				})
			 });
 }
//Home page Carousel
//var hmCarousel = document.getElementById("hmCarousel");

if ( $("#hmCarousel").length ){
	
	// $("#hmCarousel").jcarousel({
			// scroll: 3,
			// initCallback: mycarousel_initCallback,
			// itemFirstInCallback:mycarousel_itemFirstInCallback
	// });		
}

//JS function to show main page image slideshow
if ( $("#headPhotoPager").length > 0 ){
    $("#headPhotoPager").headPhotoPager();
}

//loadFlashImage();

// sIFR initialize [begin]
if(typeof sIFR == "function"){

// This is the preferred "named argument" syntax
	//sIFR.replaceElement(named({sSelector:"h2", sFlashSrc:"tradegothic.swf", sColor:"#000000", sLinkColor:"#000000", sBgColor:"#FFFFFF", sHoverColor:"#CCCCCC", nPaddingTop:20, nPaddingBottom:20, sFlashVars:"textalign=center&offsetTop=6"}));
	//sIFR.replaceElement(named({sSelector:"h1", sFlashSrc:"tradegothic.swf", sColor:"#003540", sLinkColor:"#003540", sHoverColor:"#003540", sBgColor:"#FFFFFF", nPadding : "0,0,20,0", sCase:"upper", sWmode:"transparent"}));
	//sIFR.replaceElement(named({sSelector:"h1", sFlashSrc:"/VailResorts/sites/Keystone/assets/flash/tradegothic.swf", sColor:"#74B8C7", sLinkColor:"#74B8C7", sHoverColor:"#74B8C7", sBgColor:"#FFFFFF", nPadding : "0,0,0,0", sCase:"normal", sWmode:"transparent"}));
	//sIFR.replaceElement(named({sSelector:".calendarBG th", sColor:"#FFFFFF", sFlashSrc:"tradegothic.swf", nPadding : "0,0,0,0", sCase:"normal", sWmode:"transparent"}));
//	sIFR.replaceElement(named({sSelector:"ul.nav li ul li", sFlashSrc:"", sColor:"#74B8C7", sLinkColor:"#74B8C7", sHoverColor:"#74B8C7", sBgColor:"#FFFFFF", nPadding : "0,0,20,0", sCase:"normal", sWmode:"transparent"}));
	//	sIFR.replaceElement("h1", "tradegothic.swf", "#74B8C7", null, null, null, 0, 0, 0, 0, 'upper', 'transparent');
	//sIFR.replaceElement("h2", "tradegothic.swf", "#4C8392", null, null, null, 0, 0, 0, 0);
};
// sIFR initialize [end]
	
// ***** Photo and video page Carousel
/* var myCarousel = document.getElementById("mycarousel");
if (myCarousel){
	jQuery('#mycarousel').jcarousel({scroll: 1});
			var getWidth= $("#mycarousel").width()
			var setWidth = getWidth + 200;
			$("#mycarousel").width(setWidth)
		} */

	// ***** Shadebox for thumbnil and other on main area [begin] *****		
//	  $('.shadebox').wrap(
//		  "<div class='shadeboxWrapper'>" +
//		  "<div class='shadeboxWrapper2'>" +
//		  "<div class='shadeboxWrapper3'>" +
//		  "</div></div></div>");

	 
	
//		$('.shadebox').prepend("<div class='shadeboxHeader'><b class='shadeboxTlc'></b><b class='shadeboxTrc'></b></div>");
//		$('.shadebox').append("<div class='shadeboxFooter'><b class='shadeboxBlc'></b><b class='shadeboxBrc'></b></div>");
	
	// ***** Shadebox for thumbnil and other on main area [End] *****		

	// ***** Shadebox for top and bottom blue border [begin] *****
//	 $('.shadeboxTopBotBdr').wrap(
//		  "<div class='shadeboxTopBotBdrWrapper'>" +
//		  "<div class='shadeboxTopBotBdrWrapper2'>" +
//		  "<div class='shadeboxTopBotBdrWrapper3'>" +
//		  "</div></div></div>");
	
//	 	$('.shadeboxTopBotBdr').prepend("<div class='shadeboxTopBotBdrHeader'><b class='shadeboxTopBotBdrTlc'></b><b class='shadeboxTopBotBdrTrc'></b></div>");
//		$('.shadeboxTopBotBdr').append("<div class='shadeboxTopBotBdrFooter'><b class='shadeboxTopBotBdrBlc'></b><b class='shadeboxTopBotBdrBrc'></b></div>");

	// ***** Shadebox for top and bottom blue border [end] *****		
		

	//*** Shadebox for left and right module***/
			//$('.outerGlowBox').prepend("<div class='topLeft'><span></span></div>");
			//$('.outerGlowBox').append("<div class='bottomLeft'><span></span></div>");
		
	// ***** Shadebox for left and right modules [begin] *****		
    
//	 $('.container').wrap(
//		  "<div class='middleLeft'>" +
//		  "<div class='middleRight'>" +
//		  "</div></div>");
//		$('.moduleContainer').prepend("<div class='topLeft'><span></span></div>");
//		$('.moduleContainer').append("<div class='bottomLeft'><span></span></div>");
	
	// ***** Shadebox for left and right modules [end] *****		
	
	// ***** Shadebox for left, bottom and right [begin] *****

	if ('.shadeboxLBR')
	{
//		$('.shadeboxLBR').wrap(
//		  "<div class='shadeWrapper'>" +
//		  "<div class='shadeLeft'>" +
//		  "<div class='shadeRight'>" +
//		  "</div></div></div>");
		
		$('.shadeboxLBR').parents('.shadeWrapper').after('<div class="shadeBottom"><div class="bl"></div><div class="br"></div><div class="b"></div></div>');			
	}
		

	// ***** Shadebox for left, bottom and right [end] *****


		
	// ***** Shadebox for right modules on blue gradient background [begin] *****	
//     $('.containerGra').wrap(
//		  "<div class='middleLeftGra'>" +
//		  "<div class='middleRightGra'>" +
//		  "</div></div>");
//		$('.moduleContainerGra').prepend("<div class='topLeftGra'><span></span></div>");
//		$('.moduleContainerGra').append("<div class='bottomLeftGra'><span></span></div>");		
	// ***** Shadebox for right modules on blue gradient background [end] *****		
initialize()
/*
$(".photoTabs a").each(function(){
		$(this).click(function(event){
			event.preventDefault();
			$(".photoTabs a").parent().removeClass("tabs-selected");
			var activeClass = $(this).parent().attr("class")
			$(this).parent().addClass("tabs-selected");
			var element = $("#pageCategoryContentHolder");

			$(element).remove();
			 tabUrl = $(this).attr("href");
			 var widthCon = $("#pageCategory").width();
			 var heightCon = $("#pageCategory").height();
			 var topPos = widthCon/2
			 $("#loading").css("left", topPos);
			 $("#loading").css("top", "174px");
			 $("#loading").show();
			$.ajax({
				url: tabUrl,
				cache: true,
				success: function(html){
				$("#loading").hide();
				$("#pageCategory").append(html);
				initialize();
			setSelectedThumbnail();
			  }
			});

		});
});*/
/*
$(".videoTabs a").each(function(){
		$(this).click(function(event){
			alert(1);
			event.preventDefault();
			$(".videoTabs a").parent().removeClass("tabs-selected");
			var activeClass = $(this).parent().attr("class")
			$(this).parent().addClass("tabs-selected");
			var element = $("#pageCategoryContentHolder");

			$(element).remove();
			 tabUrl = $(this).attr("href");
			 var widthCon = $("#pageCategory").width();
			 var heightCon = $("#pageCategory").height();
			 var topPos = widthCon/2
			 $("#loading").css("left", topPos);
			 $("#loading").css("top", "174px");
			 $("#loading").show();
			$.ajax({
				url: tabUrl,
				cache: true,
				success: function(html){
				$("#loading").hide();
				$("#pageCategory").append(html);
				initialize();
			setSelectedVideoThumbnail();
			  }
			});

		});
});*/


        /*
        $(".photo_thumbnail_links a").click(function(event){
			event.preventDefault();
			
			//var activeClass = $(this).parent().attr("class")
			//$(this).parent().addClass("tabs-selected");
			var element = $("#thumbnailContainer");
			$(element).remove();
			
			
			
			 newUrl = $(this).attr("href");
			

			$("#loading").show();
			$.ajax({
				url: newUrl,
				cache: true,
				success: function(html){
				$("#loading").hide();
				$("#pageCategory").append(html);
				initialize();
				setSelectedThumbnail();
			  }
			});

		});
		*/

		//Begin Snow Report Dropdown
		if ( $('#weatherWidget').length )
		{
			
			/*
			$('#weatherWidget .report a').bind('mouseover', function(){
				$('.snowReportDrop').slideDown(500);
				$('body').click (
					function(){ $('.snowReportDrop').slideUp(500); }
				)
			});
			
			$('.snowReportDrop').bind('mouseleave', function(){
				$(this).slideUp(500);
			});*/

			$('#weatherWidget .innerContainer').hoverIntent(
				function(){
					$('.snowReportDrop').slideDown(500); 				
				},
				function(){
					$('.snowReportDrop').slideUp(500); 
				}
			);

			$('.snowReportDrop dl dt:odd, .snowReportDrop dl dd:odd').css('background','#efefef');	
			$('.snowReportDrop dl dt:even, .snowReportDrop dl dd:even').css('background','#fff');	
		}
        if ( $('div.search').length ) GlobalObjects.setup();
	   //Global Objects Setup
         if ( $('#globalObjects').length ) GlobalObjects.setup();
         

		if ( $('.searchResultHeader span.tool') )
		{
			$('.searchResultHeader span.tool').bind('mouseover', function(){ 
				
				if ( !$.browser.msie) {
					$('.relevancyPopup').show(300);
					$('.relevancyPopup').mouseleave(function(){ $(this).hide(300);  });
				} else {
					$('.relevancyPopup').show();
					$('.relevancyPopup').mouseleave(function(){ $(this).hide();  });
				}
				
			});		
		}

		if ( $('#mapLoader').length ) $('#mapLoader').bind('click', loadXML );

// load modal window in a local div
if ($('.printableFullDisplay').length){
	$('.printableFullDisplay').dialog({
		bgiframe: true,
		autoOpen: false,
		width: function(){
			if($(".pentaColumn").length){ requiredWidth = 922; }
			else if($(".quadColumn").length){requiredWidth = 752; }
			else{ requiredWidth = 564;}
			return requiredWidth;
			},
		modal: true,
		resizable: false,
		position: 'center',
		closeOnEscape: true,
		onClose: function(){
			$(".printLink").find("img").remove()
			$(".printableArea").removeClass("noPrint");
			$("#mainContainer").removeClass("noPrint");
		}
	});
}
	// open a modal window containing the page data 

if ($('.print').length){
    $('.print').bind('click', function(e){
        e.preventDefault();
		
		$(".printableDisplay").html( $(".printableArea", "#mainContainer").clone() );
		$(".printableArea").addClass("noPrint");
		$("#logo img").clone().insertAfter(".printLink a");
		$('.printableFullDisplay').dialog('open');
		$('.detailedForecast ul').hide();
		$('.printableFullDisplay .detailedForecast ul').show();
        return false;
    });
}
// Print the page 
if ($('.printNow').length){
	$('.printNow').bind('click', function(e){
		e.preventDefault();
        self.print();
        return false;
    });
}
//onClose function
$('.ui-dialog-titlebar-close').bind('click', function(){
		$(".printLink").find("img").remove();
		$(".printableArea").removeClass("noPrint");
		$("#mainContainer").removeClass("noPrint");	
		$('.detailedForecast ul').show();
													 });

// ***** Photo and video page Carousel
var myCarousel = document.getElementById("mycarousel");
if (myCarousel){
	jQuery('#mycarousel').jcarousel({
	    scroll: 1,
	    initCallback: function(carousel){
	        tabCarousel = carousel;
	    }
	});
			var getWidth= $("#mycarousel").width()
			var setWidth = getWidth + 200;
			$("#mycarousel").width(setWidth)
}


//planYourTripBarWrapper
$('.closeBtn').click(function(){
   if ((jQuery.browser.msie) && (parseInt(jQuery.browser.version)==6)){
		$('#planYourTripBarWrapper').css('z-index','-1');
   }
   else {
	   	$('#planYourTripBarWrapper').css('z-index','1');
   }
})

//add class to filter item on dining page
if ( $(".keywordFilter ul").length  ) $(".keywordFilter ul").find('li:eq(1)').addClass('filterLi');
if ( $(".generalContent").length  ){$(".generalContent h2").next(".introText").css({"padding-left": "0px", "padding-top":"0px"})};
	$('[id$=txtDepartDate]').bind("change", function(){
	    if($('[id$=txtDepartDate]').val() != '' && IsDateMMDDYYYY($('[id$=txtDepartDate]').val())) {
            var NewDate=new Date( $('[id$=txtDepartDate]').val());
            NewDate.setDate(NewDate.getDate()+1);
            $('[id$=txtReturnDate]').datepicker('option', 'minDate', NewDate );
            $('[id$=txtReturnDate]').datepicker('setDate', NewDate);            
        }
    });
    if(typeof($('[id$=txtDepartDate]').datepicker) != "undefined" ){
        $('[id$=txtDepartDate]').datepicker("option", "onSelect", function(){
            if($('[id$=txtDepartDate]').val() != '' && IsDateMMDDYYYY($('[id$=txtDepartDate]').val())) {
                var NewDate=new Date( $('[id$=txtDepartDate]').val());
                NewDate.setDate(NewDate.getDate()+1);
                $('[id$=txtReturnDate]').datepicker('option', 'minDate', NewDate );
                $('[id$=txtReturnDate]').datepicker('setDate', NewDate);                
            }
        });
    }
});//END Document Ready

function initialize(){


//	if($('#middleTabsContainer').text()){
//		$('#middleTabsContainer').tabs(1);
//	}; 
    if($('#middleTabsContainer').length){
	    var idx = 1;
	    var hash = document.location.hash;
	    var selectedAnchor = $('#middleTabsContainer ul.middleTabs > li:first > a');
	    if (hash.length > 1){
		    var id = hash.split("#")[1];
		    selectedAnchor = $('#middleTabsContainer ul.middleTabs > li > a[href$=#' + id + ']');
		    if ( selectedAnchor.length > 0 ){
			    idx = $('#middleTabsContainer ul.middleTabs > li > a').index(selectedAnchor) + 1;
		    }
	    }
        $('#middleTabsContainer').tabs(idx);
	    if ( selectedAnchor.length > 0 ){
			    if ( idx > 1){
				    selectedAnchor.trigger('click');
			    }
		    }
	    $('#middleTabsContainer ul.middleTabs li:last').addClass('last');
    };
	if ( $('#homepageColumn1').length )
	{
		$('#middleTabsContainer .middleTabs').wrap('<div class="middleTabsWrapper"></div>');
		$('#middleTabsContainer .middleTabsWrapper').tabs(1);

	}

	
	// ***** Shadebox for thumbnil and other on main area [begin] *****	
//if ($(".searchBoxHolder .shadebox").parent().attr("class")!="shadeboxWrapper3")
//	{
//	
//	if ($(".searchBoxHolder .shadebox .shadeboxHeader").length == 0)
//	{
////		  $('.searchBoxHolder .shadebox').wrap(
//		  "<div class='shadeboxWrapper'>" +
//		  "<div class='shadeboxWrapper2'>" +
//		  "<div class='shadeboxWrapper3'>" +
//		  "</div></div></div>");

//		$('.searchBoxHolder .shadebox').prepend("<div class='shadeboxHeader'><b class='shadeboxTlc'></b><b class='shadeboxTrc'></b></div>");
//		$('.searchBoxHolder .shadebox').append("<div class='shadeboxFooter'><b class='shadeboxBlc'></b><b class='shadeboxBrc'></b></div>");
//		}
//	}
	// ***** Shadebox for thumbnil and other on main area [End] *****	
	
	// ***** Left Navigation [begin] *****
	$("#leftNav ul li ul").hide();
	
	$("#leftNav ul li").hover(
      function () { $(this).addClass("on"); }, 
      function () { $(this).removeClass("on"); }
    );

	$("#leftNav li.hasChild").prepend("<img src='/VailResorts/sites/Heavenly/assets/img/plus_icon.jpg' alt='' class='treeView' />");

	$("#leftNav ul li img").click(function(){
		$(this).next("a").next("ul").toggle();

		if ($(this).attr("src")=="/VailResorts/sites/Heavenly/assets/img/minus_icon.jpg") { 
				$(this).attr("src","/VailResorts/sites/Heavenly/assets/img/plus_icon.jpg"); 
				$(this).parents("li").removeClass("current");
			}
		else { 
				$(this).attr("src","/VailResorts/sites/Heavenly/assets/img/minus_icon.jpg");
				$(this).parents("li").addClass("current");
			}
		});

	$("#leftNav .shadeboxInner > ul").show(); /*pn artf906568 :*/
	$("#leftNav .hasChild.current.selected ul").show(); /*st artf1008365 :*/
	$("#leftNav .hasChild.current img").attr('src','/VailResorts/sites/Heavenly/assets/img/minus_icon.jpg'); /*st artf1008578*/
	
	
// ***** Left Navigation [end] *****

// ***** Top Navigation [begin] *****
	     if ($.browser.msie) {
        $("#topNav ul li a").unbind("click").bind("click", function(event) {
             event.stopPropagation();
        });
        $("#topNav ul li").unbind("click").bind("click", function(event) {
			var url = $(this).find("a").attr("href");
    		if($(this).find("a").attr("target") == '_blank'){
				window.open(url);
			} else {
				document.location.href = $(this).find("a").attr('href');	
			}
        });
    } 



	$("#topNav > li").hover(
      function () {
		$(this).addClass("on");
		if ((jQuery.browser.msie) && (parseInt(jQuery.browser.version)==6)){
			//png hack for ie6 fixes the height for topnav which prevents dropdowns from showing up. Height will have to be dynamically rendered thru js
			$('#topNavContainner').height(55 + $(this).find('ul').height());
		}
		$(this).find('ul li').hover(
			function(){
				$(this).addClass("hoverOn");
			},
			function(){
				$(this).removeClass("hoverOn");
				$(this).unbind('click');
			}
		).bind( 'click', function(){
		    
			location.href = $(this).find('a').attr('href');
		});
	}, 
      function () {
       $(this).removeClass("on");
	   if ((jQuery.browser.msie) && (parseInt(jQuery.browser.version)==6)){
		   $('#topNavContainner').css('height','1%')
	   }
      }
    )
	
	

// ***** Top Navigation [begin] *****

/*Plan a vacation on focus*/
$('#planYourTripBar input').each(function(){
	$(this).bind("focus", function(){
                    
					var defaultText = '';
					defaultText = $(this).val();
					
					if (defaultText=="Arrive:" || defaultText=="Depart:" || defaultText=="# of adults" || defaultText=="# of kids" ){
					$(this).val('');
					}
					$(this).blur(function(){
						var userInput =$(this).val();
						if (userInput == ''){
						
							
							if ($(this).attr("id")=="PlanYourTrip1_txtArriveDate" || $(this).attr("id")=="PlanYourTrip_txtArriveDate"){
								$(this).val("Arrive:");
							}
							if ($(this).attr("id")=="PlanYourTrip1_txtDepartDate" || $(this).attr("id")=="PlanYourTrip_txtDepartDate"){
								$(this).val("Depart:");
							}
						
						}
					})
					
				});
			 });
/*plan a vacation on focus end*/

	// ***** Promo toggling [begin] *****
	  $('#vacationDeal .promo').hide();
	  $('#vacationDeal h3').click(function(){
		var $this = $(this); 
		if( $this.is('.expand') ) {
		$('.promo').toggle(400);								
		$this.removeClass('expand');
		$this.addClass('collapse');
		}
		else {
		$('.promo').toggle(400);
		$this.removeClass('collapse');
		$this.addClass('expand');
		}
		return false;
		}); 
	
	// ***** Promo toggling [End] *****	  
  
	// ***** Accordion [begin] *****

		if ($('.accordion').text()) {
		    $(".accordion").accordion({
		        autoHeight: false,
		        change: function() {
		            $('.accordion .mediaAssetContainer').css("overflow", "visible");
		        },
		        active: 0
		    });
		};		
	// ***** Accordion [End] *****		
	  
	// ***** Date Picker [begin] *****
	// ******* artf971517 [begin] *****
	
	if($("input").hasClass("withCalendar")){
	    if ( $("[id$=hdMaxDate]").length > 0 ){
	        maxDate = $("[id$=hdMaxDate]").val();
	    }
		if (!maxDate){
			var maxDate = "+365";
		} else {
			maxDate = new Date(maxDate);
		}
	    if ( $("[id$=hdMinDate]").length > 0 ){
	        minDate = $("[id$=hdMinDate]").val();
	    }
		if (!minDate){
			var minDate = "+1"; //PS
		} else {
			minDate = new Date(minDate);
		}
		
		$(".withCalendar").datepicker({
			showOn: 'both', 
			buttonImage: '/VailResorts/sites/heavenly/assets/img/icon_calender.gif', 
			buttonImageOnly: true,
			defaultDate: minDate,
			maxDate: maxDate,
			minDate: minDate,
		    onSelect: function(dateText, inst) {
	            return false;
	        }
		});
		$(".withCalendar").unbind("keydown").bind("keydown", function(e){
            if (e.keyCode == 13) { e.preventDefault(); return false; }
            else if (e.keyCode == 27) { $(this).datepicker('hide'); return false;}
            return true;
        });
	}
	
	// ******* artf971517 [end] *****
	
	
	
//	if($("input").hasClass("withCalendar")){
//		$(".withCalendar").datepicker({showOn: 'button', buttonImage: '/VailResorts/sites/heavenly/assets/img/spacer.gif', buttonImageOnly: true});
//	}
  	//	$("#arrive").datepicker({showOn: 'button', buttonImage: '/VailResorts/sites/Keystone/assets/img/icon_calender.gif', buttonImageOnly: true});
	//	$("#depart").datepicker({showOn: 'button', buttonImage: '/VailResorts/sites/Keystone/assets/img/icon_calender.gif', buttonImageOnly: true});
		
	// ***** Date Picker [end] *****		

	

// ***** Tabs
/*pn - homepage carousel fix */
if($('.middleTabsWrapper').text()){
	$('.middleTabsWrapper').tabs(1);	
};
if($('#vacationDealsHomepage').text()){
	$('#vacationDealsHomepage').tabs(1);
	if ($(".vacationDeals >li").attr("class")=="tabs-selected"){
		$(".vacationDeals >li.tabs-selected").children(":first").prepend("<span class='leftLine'></span><span class='rightLine'></span>");
	}
	$(".vacationDeals a").click(function(){
		
	$(".leftLine").remove();
	$(".rightLine").remove();
	$(this).prepend("<span class='leftLine'></span><span class='rightLine'></span>");

 })
};

/* PK [begin] */
if($('#mainTabsContainer').text()){
	$('#mainTabsContainer').tabs(1);
};
	// hover effect for photogallery thumbnails
		$("ul.thumbnails li" ).hover(
				function () {
						$(this).addClass('imgOver');					
					},
					function () {
						$(this).removeClass('imgOver');
					});
	// hover effect for web cam thumbnails
		$("ul.webCam_thumbs li" ).hover(
				function () {
						$(this).addClass('imgOver');					
					},
					function () {
						$(this).removeClass('imgOver');
					});
	// hover effect for photogallery thumbnails
		$("ul.thumbsAlign li" ).hover(
			
				function () {
					$(this).children(":first").addClass('bdrThumOn');					
					},
					function () {
					
					var onClass =$(this).children(":first").attr("class")
					if (onClass == "bdrThumOn"){
						$(this).children(":first").removeClass('bdrThumOn');
						$(this).children(":first").addClass('bdrThumOn');
					}else{
						$(this).children(":first").removeClass('bdrThumOn');
					}
					});

		
/* 



JavaScript methods of modal dialgue window for photo slideshow page
----------------------------------------------------------------------*/
/*
//to show the div
$(".viewSlideShow").bind("click", function() {
	$(".overlayDiv").css("height", $(document).height());
	$(".overlayDiv").css("width", $(document).width());
	$(".overlayDiv").css("opacity","0.5");	
	$(".overlayDiv").removeClass("hideDiv");	
	$(".modalDiv").removeClass("hideDiv");
	$("#control>li.play").addClass('current');
	var modalWin = $(".modalDiv");
	var height = $(window).height();
	var width = $(document).width();
	leftPos = width/2 - (modalWin.width() / 2) ; // half width - half element width
	topPos = height/2 - (modalWin.height() / 2); // similar
	$(".modalDiv").css({'left':leftPos, 'top': topPos})
		
		});	

//to close the div
$(".linkClose").bind("click", function (){
	$(".overlayDiv").addClass("hideDiv");	
	$(".modalDiv").addClass("hideDiv");
	$(".viewLargeModal").addClass("hideDiv");
	$("#control>li").removeClass('current');
	$("#control>li.play").addClass('current');
	});
	
//View Large
//to show the div
$(".viewLargerLink").bind("click", function() {
	$(".overlayDiv").css("width", $(document).width());
	$(".overlayDiv").css("height", $(document).height());
	$(".overlayDiv").css("opacity","0.5");	
	$(".overlayDiv").removeClass("hideDiv");	
	$(".viewLargeModal").removeClass("hideDiv");
	var modalWin = $(".viewLargeModal");
	var height = $(window).height();
	var width = $(document).width();
	leftPos = width/2 - (modalWin.width() / 2) ; // half width - half element width
	topPos = height/2 - (modalWin.height() / 2); // similar
	$(".viewLargeModal").css({'left':leftPos, 'top': topPos})	
	});	

//Image switching photogallery
$("#thumbnailContainer a").click(function(event) {
	event.preventDefault();
	$(this).parents("li").parents("ul").find("li").removeClass("selected");
	$(this).parent("li").addClass("selected");
	
	setSelectedThumbnail();
	setSelectedVideoThumbnail();
	
	});
*/
//Video switching videogallery / *****????? 
$("#thumbnailContainer a").click(function(event) {
	event.preventDefault();
	var image = $(this).children(":first").attr("src");
	$("#videoContainer").children(":first").attr("src", image);
	});

//Toggle blank fill
$('input.txtBoxSearch').focus(function(){

		var defaultText = '';
		defaultText = $(this).val();
		$(this).val('');

		$("input").blur( function () {
		var userInput = $(this).val();

		if (userInput == ''){
			$(this).val(defaultText);
			defaultText = '';
		}
	});

 });
/*
//Slideshow control//
$("#control>li" ).hover(
		function () {
				$(this).addClass('active');
					},
		function () {
			$(this).removeClass('active');
		});	
	

$(".viewSlideShow").click(function (){
	 slideShow = setInterval( "slideSwitch()", 3000 );
	 	   $("#control>li").bind("click", function(){
	   		$("#control>li").removeClass('current');
	   		var currentId = $(this).attr("class");
			if (currentId == "pause active"){
				clearInterval(slideShow);
				$(this).addClass('current');
			}

			if (currentId == "play active"){
				clearInterval(slideShow);
				slideShow = setInterval( "slideSwitch()", 3000 );
				$(this).addClass('current');
			}

			if (currentId == "stop active" ){
				clearInterval(slideShow);
				$("#slideshow>img").each(function(){
					var activeClass = $(this).attr("class")
					if (activeClass =="active"){
						$(this).removeClass("active");
						}
				})
				$('#slideshow IMG:first').addClass("active");
				$(this).addClass('current');
			}
			
			if (currentId == "forward active" ){
				clearInterval(slideShow);
				$("#slideshow>img.active").next().addClass("active");
				$("#slideshow>img.active").prev().removeClass("active");
				//setInterval( "slideSwitch()", 3000 );
			
				}
			if (currentId == "backward active" ){
				clearInterval(slideShow);
				$("#slideshow>img.active").prev().addClass("active");
				$("#slideshow>img.active").next().removeClass("active");
			
				}
	   })
})*/

//Tab Ajax

//ski snow hover
// Show/Hide Weather report on day wise *****
		$("#WR1").hide();
		$("#WR2").hide();
		$("#WR3").hide();		
		$("#WR4").hide();				
		$("#WR5").hide();	
		$("#WR6").hide();
		function getPosition(no){
			//var pos = $("#weatherReportData").position();
			var defaultLeft =-85
				if (no==0){
				$(".WinfoBox1").css({"left":"0px"});
				} else{
					 if ($.browser.version == "6.0"){
						$(".WinfoBox1").css({"left":(defaultLeft*no) +"px"}); 
					 } else{
					$(".WinfoBox1").css({"left":((defaultLeft*no)-no) +"px"});
					 }
				}
		}
		$("#detailedForecast ul li#dayone" ).hover(
		function () {
				$("#WR1").show();
				$(this).children(":first").addClass("snowShadowOn");
				getPosition(0)
				},
		function () {
			$("#WR1").hide(); 
			$(this).children(":first").removeClass("snowShadowOn");
		});	
		
		$("#detailedForecast ul li#daytwo" ).hover(
		function () {
				$("#WR2").show();
				$(this).children(":first").addClass("snowShadowOn");
				getPosition(1)
				},
		function () {
			$("#WR2").hide(); 
			$(this).children(":first").removeClass("snowShadowOn");
		});	
		
  		$("#detailedForecast ul li#daythree" ).hover(
		function () {
				$("#WR3").show();
				$(this).children(":first").addClass("snowShadowOn");
				getPosition(2)
				},
		function () {
			$("#WR3").hide(); 
			$(this).children(":first").removeClass("snowShadowOn");
		});	
		
  		$("#detailedForecast ul li#dayfour" ).hover(
		function () {
				$("#WR4").show();
				$(this).children(":first").addClass("snowShadowOn");
				getPosition(3)
				},
		function () {
			$("#WR4").hide(); 
			$(this).children(":first").removeClass("snowShadowOn");
			
		});			

		$("#detailedForecast ul li#dayfive" ).hover(
		function () {
				$("#WR5").show();
				$(this).children(":first").addClass("snowShadowOn");
				getPosition(4)
				},
		function () {
			$("#WR5").hide(); 
			$(this).children(":first").removeClass("snowShadowOn");
			
		});	
		
		$("#detailedForecast ul li#daysix" ).hover(
		function () {
				$("#WR6").show();
				$(this).children(":first").addClass("snowShadowOn");
				getPosition(5)
				},
		function () {
			$("#WR6").hide(); 
			$(this).children(":first").removeClass("snowShadowOn");
			
		});	
		
		// Add Remove for image hover*****

		
}

/* PK [end] */
/*
function setSelectedThumbnail(){
	var image = $(".thumbnailContainer ul li.selected a").attr("href");
	$("#previewImageContainer .previewImage").attr("src", image);
	
	var changedCaption = $(".thumbnailContainer ul li.selected div.photoInfoThumbnail").html();
	$(".photoCaption").html(changedCaption);
	
	var photoNumber = $(".thumbnailContainer ul li.selected div.photoInfoThumbnail span.photoNumber").html();
	var totalCategoryPhotos = $("input.totalCategoryPhotos").val();
	var photoPagingNumber = photoNumber +" OF " + totalCategoryPhotos;
	$(".photoPagingNumber").html(photoPagingNumber);
	
	
	var firstPhotoNumber = $(".thumbnailContainer ul li:first div.photoInfoThumbnail span.photoNumber").html();
	var lastPhotoNumber = $(".thumbnailContainer ul li:last div.photoInfoThumbnail span.photoNumber").html();
	
	var categoryPagingNumber = firstPhotoNumber +"-"+ lastPhotoNumber +" OF " + totalCategoryPhotos;
	$(".categoryPagingNumber").html(categoryPagingNumber);
	}
*/
function setSelectedVideoThumbnail(){
	var image = $(".thumbnailContainer ul li.selected a").attr("href");
	$("#previewImageContainer .previewImage").attr("src", image);
	
	var totalCategoryPhotos = $("input.totalCategoryVideos").val();

	var changedCaption = $(".thumbnailContainer ul li.selected div.videoInfoThumbnail").html();
	$(".videoCaption").html(changedCaption);
		
	var firstPhotoNumber = $(".thumbnailContainer ul li:first div.videoInfoThumbnail span.videoNumber").html();
	var lastPhotoNumber = $(".thumbnailContainer ul li:last div.videoInfoThumbnail span.videoNumber").html();
	
	var categoryPagingNumber = firstPhotoNumber +"-"+ lastPhotoNumber +" OF " + totalCategoryPhotos;
	$(".categoryPagingNumber").html(categoryPagingNumber);
	}

// Apply drop shadow to the children of the passed obj cointainer (used for example on html elements loaded via ajax)
function applyShader(obj){
	// ***** Shadebox for thumbnil and other on main area [begin] *****		
//	$(obj).find('.shadebox').wrap(
//		  "<div class='shadeboxWrapper'>" +
//		  "<div class='shadeboxWrapper2'>" +
//		  "<div class='shadeboxWrapper3'>" +
//		  "</div></div></div>");
//		$(obj).find('.shadebox').prepend("<div class='shadeboxHeader'><b class='shadeboxTlc'></b><b class='shadeboxTrc'></b></div>");
//		$(obj).find('.shadebox').append("<div class='shadeboxFooter'><b class='shadeboxBlc'></b><b class='shadeboxBrc'></b></div>");
}

GlobalObjects =
{
	temp:'',
	setup:function()
	{
	    	    
        $('#globalObjects').find('input[type=text]').each( function() {
			jQuery(this).bind('click', function(){
				GlobalObjects.temp = jQuery(this).val();
				jQuery(this).val('');
			});

			jQuery(this).bind('blur', function(){
				if ( ( GlobalObjects.temp != null ) && ( jQuery(this).val()=='' ) )
				{
					jQuery(this).val(GlobalObjects.temp);
				}
			});
		});

        
		if ( $('.pageTools').length )
		{
		    
			//$('.pageTools .print a').bind('click', function(){ self.print() });
		    $('.pageTools .share').bind('mouseover', function() {
		        $('#at15s').bgiframe(); 
				var shareTop = $(this).position().top
				var shareLeft = $(this).position().left
				
				if ( !$.browser.msie) {
					$('.sharePopup').show(300);
					$('.sharePopup').css({ top:shareTop-13, left: shareLeft-14});
					$('.sharePopup').mouseleave(function(){ $(this).hide(300);  });
					
				} else {
					$('.sharePopup').show();
					if($.browser.version == "6.0"){ 
					$('.sharePopup').css({ top:shareTop-6, left: shareLeft-8});
					}
					else{
					$('.sharePopup').css({ top:shareTop-14, left: shareLeft-14});
					}
					$('.sharePopup').mouseleave(function(){ $(this).hide();  });
				}
				
			});					
		}
		
		setTimeout(function(){ $('.sharePopup .content').bgiframe(),1500});
		
        $('.sendToShare').click(function(event){
    
      event.preventDefault();
      
      var url;
      var protocol = 'http://'
      var targetUrl;   
      title=document.title;  
    
        if (($('.previewImageWrap').length) &&(!($('.media').length)))
	    {   
	        url=protocol + location.hostname + '/' +  $('.previewImageWrap').find('img').attr('src');
	    }	
	    else if ($('.webCam_imgHolder').length)
	    {
	        url=$('.webCam_imgHolder').find('img').attr('src');	    
	    }  
        else {
            url = window.location; 
        } 
	  
	  var $this= $(this).parents("li").attr("class");
	  switch($this)
	  {
	    case 'facebook':	                    	                     
	                     targetUrl='http://www.facebook.com/sharer.php?u='+encodeURIComponent(url)+'&t='+encodeURIComponent(title);
                         window.open(targetUrl,'sharer','location=no,menubar=no,resizable=no,scrollbars=yes,status=no ,toolbar=no,width=626,height=436');
                         break;
        case 'myspace': 
                         targetUrl = 'http://www.myspace.com/index.cfm?fuseaction=postto&' + encodeURIComponent(title)+ encodeURIComponent(url) + '&u=' + encodeURIComponent(url) + '&l=' + 3;
                         window.open(targetUrl,'','location=no,menubar=no,resizable=no,scrollbars=yes,status=no ,toolbar=no,width=626,height=436');
                         break;
        case 'digg':
                         targetUrl = 'http://digg.com/submit?url=' + url + '&title'+title;
                         window.open(targetUrl,'','location=no,menubar=no,resizable=no,scrollbars=yes,status=no ,toolbar=no,width=626,height=436');            
                         break; 
        case 'delicious':
                         targetUrl='http://delicious.com/save?v=5&amp;noui&amp;jump=close&amp;url='+encodeURIComponent(url)+'&amp;title='+encodeURIComponent(title);
                         window.open(targetUrl,'delicious','location=no,menubar=no,resizable=no,scrollbars=yes,status=no ,toolbar=no,width=550,height=550');
                         break;
        case 'flickr':
                         targetUrl='http://www.flickr.com/photos/';
                          window.open(targetUrl,'flickr','location=no,menubar=no,resizable=no,scrollbars=yes,status=no,toolbar=no,width=550,height=550');
                         break;             
        default:
                         alert("Invalid Choice");
	    
	  }
	  
	 
});
        $('ul.search').find('input#search').each( function() {
			jQuery(this).bind('click', function(){
				GlobalObjects.temp = jQuery(this).val();
				jQuery(this).val('');
			});
			
			jQuery(this).bind('blur', function(){
				if ( ( GlobalObjects.temp != null ) && ( jQuery(this).val()=='' ) )
				{
					jQuery(this).val(GlobalObjects.temp);
				}
			});
		});
	
	}
	
}


/* This function is responsible for showing first image in creative
   space when browser has no flash player. */
//function loadFlashImage(){
//   if(!$('object#flashObj').length){
//        if($('#flashImageURL').length>0){
//           $('#flashObj').append('<a target="" href="'+$('#flashImageURL').val()+'"> <img src="'+$('#flashLoaderParam').val()+'" alt="flashImage" /> </a>');
//        }
//        else{
//           $('#flashObj').append('<img src="'+$('#flashLoaderParam').val()+'" alt="flashImage" />');
//        }
//        $('.flsLinks').hide();
//   }
//}

function BindKeyPressEventWithTextBox(e, buttonid){
      var evt = e ? e : window.event;
      var bt = document.getElementById(buttonid);
      if (bt){
          if (evt.keyCode == 13){
                $(bt).click();                
                return false;
          }
      }
  }


  function getErrorMessage(xhr, status, error) {
      var err = eval('xhr.responseText');
      var errMsg = ' ';

      if (status.toLowerCase() == "timeout".toLowerCase()) {
          errMsg = "An unexpected error has occurred. Please try after some time or contact support center for assistance.";
          return errMsg;
      }

      if (err != undefined && err.Message != undefined) {
          return err.Message;
      }

      return errMsg;
  }
  
  //This function verifies if date entered is in mm/dd/yyyy format or not.
function IsDateMMDDYYYY(dtStr) {    

    var dtCh = "/"; 

    var minYear = 1900;
    var maxYear = 2100;

    var daysInMonth = DaysArray(12);
    var pos1 = dtStr.indexOf(dtCh);
    var pos2 = dtStr.indexOf(dtCh, pos1 + 1);
    var strMonth = dtStr.substring(0, pos1);
    var strDay = dtStr.substring(pos1 + 1, pos2);
    var strYear = dtStr.substring(pos2 + 1);
    strYr = strYear;
    if (strDay.charAt(0) == "0" && strDay.length > 1) strDay = strDay.substring(1);
    if (strMonth.charAt(0) == "0" && strMonth.length > 1) strMonth = strMonth.substring(1);
    for (var i = 1; i <= 3; i++) {
        if (strYr.charAt(0) == "0" && strYr.length > 1) strYr = strYr.substring(1);
    }
    month = parseInt(strMonth);
    day = parseInt(strDay);
    year = parseInt(strYr);
    if (pos1 == -1 || pos2 == -1) {        
        return (false);
    }
    if (strMonth.length < 1 || month < 1 || month > 12) {        
        return (false);
    }
    if (strDay.length < 1 || day < 1 || day > 31 || (month == 2 && day > daysInFebruary(year)) || day > daysInMonth[month]) {        
        return (false);
    }
    if (strYear.length != 4 || year == 0 || year < minYear || year > maxYear) {        
        return (false);
    }
    if (dtStr.indexOf(dtCh, pos2 + 1) != -1 || isInteger(StripCharsInBag(dtStr, dtCh)) == false) {        
        return (false);
    }
    return (true);
}
function StripCharsInBag(s, bag) {
    var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++) {
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return (returnString);
}

function xreplace(checkMe,toberep,repwith) {
	var temp=checkMe;
	var i=temp.indexOf(toberep);
	while (i>-1) {
		temp = temp.replace(toberep, repwith);
		i = temp.indexOf(toberep, i + repwith.length + 1)
	}
	return temp;
}