/* 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 () {
	/* BEGIN Copied from heavenly_emailToFriend.js */
	//setting up the modal window attributes
	$('.emailAFriend').dialog({
		bgiframe: true,
		autoOpen: false,
		width: 470,
		height: 380,
		modal: true,
		resizable: false,
		position: 'center',
		closeOnEscape: true,
		draggable: false
	});

	$('.emailAFriendopenModal').click(function (e) {
		e.preventDefault();

		// grabs url from href and loads it into the modal window
		var urlContent = $(this).attr('href');
		$('.emailAFriend').dialog('close');

		$('.emailAFriend iframe')
	        .attr('src', urlContent)
	        .attr('width', '100%')
	        .attr('height', '100%')
	        .attr('scrolling', 'no')
	        .attr('frameborder', 'no');

		$('.emailAFriend iframe').bind("load", function () {
			bindFocus();
		});

		$('.emailAFriend').dialog('open');

		return false;
	});

	function bindFocus() {
		$('input.emailInputContent').each(function () {
			$(this).bind("focus", function () {

				var defaultText = '';
				defaultText = $(this).val();

				if (defaultText == "Email address" || defaultText == "Name") {
					$(this).val('');
				}
				$(this).blur(function () {
					var userInput = $(this).val();
					if (userInput == '') {
						var targetText = $(this).prev().text();
						if (targetText == "To") {
							$(this).val("Email address");
						}
						if (targetText == "From") {
							$(this).val("Name");
						}
						if (targetText == "") {
							$(this).val("Email address");
						}

					}
				})

			});
		});
	}
	/* END Copied from heavenly_emailToFriend.js */

	/* 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;
					}
				}
			}
		});
	}
	/** 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*/

	$(".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")
		}
	})

	function mycarousel_itemFirstInCallback(carousel, item, idx, state) { };

	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))
				}
			})
		});
	}

	//JS function to show main page image slideshow
	if ($("#headPhotoPager").length > 0) {
		$("#headPhotoPager").headPhotoPager();
	}

	if ('.shadeboxLBR') {
		$('.shadeboxLBR').parents('.shadeWrapper').after('<div class="shadeBottom"><div class="bl"></div><div class="br"></div><div class="b"></div></div>');
	}

	initialize();

	//Begin Snow Report Dropdown
	if ($('#weatherWidget').length) {
		$('#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();

			// Get the printable area
			var $printableArea = $(".printableArea").clone();

			// Allows for a page control to override the printable area --- FRUX I Addition
			if ($(".printableAreaOverride").length > 0) {
				$printableArea = $(".printableAreaOverride").clone();

				var additionalContent = "";
				if ($(".printableAreaAdditionalContent").length > 0)
					additionalContent = "<div>" + $(".printableAreaAdditionalContent").html() + "</div>";

				var containerDivStart = "<div id=\"" + $printableArea.attr("id") + "\" + class=\"" + $printableArea.attr("class") + "\">";
				var containerDivEnd = "</div><div class=\"clear\"></div>";

				$printableArea.html(containerDivStart + additionalContent + $printableArea.html() + containerDivEnd);
			}

			// Sets the printable area to the dialog
			var printableHTML = $printableArea.html();
			$(".printableDisplay").html(printableHTML);
			$(".printableArea").addClass("noPrint");
			$("#logo img").clone().insertAfter(".printLink a");
			$('.printableFullDisplay').dialog('open');
			$('.detailedForecast ul').hide();
			$('.printableFullDisplay .detailedForecast ul').show();
			$('.ui-widget-overlay').width($(document).width());
			$('.ui-widget-overlay').height($(document).height());
			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();
	});
	
	    // Sets AutoPrint
    var hash = window.location.hash;
    if (hash == "#autoprint") {
        self.print();
    }

	// ***** 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)
	}

	//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" }) };
	
});   //END Document Ready

function initialize() {
	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);
	}

	// ***** 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%')
      	}
      }
    )

	// ***** 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] *****
	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;
		});
	}

	// ***** 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');
			}
		}
	);

	//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 = '';
			}
		});
	});

	//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 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");
	});
}

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) { }

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);
				}
			});
		});
	}
}

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) {
	if (dtStr == null) return false;
	else if (dtStr == "") return false;
	else {
		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;
}
