$(document).ready(function(){
	var fullHeight = parseInt($("#centerBar").css("paddingBottom")) + 125;
	$("#innercontent").animate({height: fullHeight + "px"},fullHeight*4.2,function(){
		$(".itinStop").each(function(){
			$(this).animate({left: "0px"},250,"linear",function(){
				$(this).children(".itinContent").animate({left: "0px"},250,"linear",function(){
					$("#dither").css({ height: $(document).height() });
					$("#dither").css({ display: "block", opacity: 0 });
					$("#dither").css({display: "none"});
				});
			});
		});
	});
	
	$(".itinContent").click(function(){
		$("#largeTitle").text($(this).children("img").siblings(".itinText").children(".shortText").text());
		$("#largeFullText").html(URLDecode($(this).children("img").attr("full")));
		if($(this).children("img").attr("link")!=""){
			if($(this).children(".itinText").text().indexOf("Priv") > -1){
				$("#itinlink img").attr("src","/images/itinviewmore.jpg");
			} else {
				$("#itinlink img").attr("src","/images/itinviewmenu.jpg");
			}
			
			$("#itinlink").attr("href",$(this).children("img").attr("link"));
			$("#itinlink").css({display: "block"});
		} else {
			$("#itinlink").css({display: "none"});
		}
		$("#contentImage").attr("src",$(this).children("img").attr("lgsrc"));
		$("#dither").css({ height: $(document).height() });
		$("#dither").css({ display: "block", opacity: 0 }).fadeTo(300, 0.8,function(){
			var startTop = $(document).height()/2;
			var startLeft = $(document).width()/2;
			$("#largeContent").css({top: startTop + "px", left: startLeft + "px",display: "block"});
			$("#largeContent").animate({top: startTop-351 + "px", left: startLeft-145 + "px", width: "703px", height: "291px"},1000);
			$("#largeContent img").css({display: "block"});
			$("#largeText").css({display: "block"});
		});
		$("#largeFullText a").each(function(){
			$(this).attr("target","_blank");
		});
	});
	
	$("#itinclose").click(function(){
		var startTop = $("#innercontent").height()/2;
		var startLeft = $("#pagecontent").width()/2;
		$("#largeContent").animate({top: startTop + "px", left: startLeft + "px", width: "0px", height: "0px"}, 1000, function(){
			$("#dither").fadeOut(300);
			$("#largeContent img").css({display: "none"});
			$("#largeText").css({display: "none"});
		});
	});
});

function URLDecode(url) //function decode URL
{
// Replace + with ' '
// Replace %xx with equivalent character
// Put [ERROR] in output if %xx is invalid.
var HEXCHARS = "0123456789ABCDEFabcdef";
var encoded = url;
var plaintext = "";
var i = 0;
while (i < encoded.length) {
var ch = encoded.charAt(i);
if (ch == "+") {
plaintext += " ";
i++;
} else if (ch == "%") {
if (i < (encoded.length-2)
&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1
&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
plaintext += unescape( encoded.substr(i,3) );
i += 3;
} else {
alert( 'Bad escape combination near ...' + encoded.substr(i) );
plaintext += "%[ERROR]";
i++;
}
} else {
plaintext += ch;
i++;
}
} // while

return plaintext;
}; 
