willow.fixPodiumNav();

willow.ready(function($) {

	 // Podium search
    $('#search').pdSearch({showButton:true, showButtonClass:'searchButton', showButtonText:''});
	
	var menuOptions = {
		direction:"down",
		showL3s:false,
		currentL1:pdGlobal.currentPages[0].id
	};
	
	willow.getMenu("133064|120227|122834|131308|131309|131310|133428|131311",function(data){
		$("#L1").menu(data.menu,menuOptions);

		var footMenu = data.menu,menuString = "";
		for(var i = 0; i < footMenu.length; i++){			
			menuString+="<li class='footL1li'><a id='footL1_"+footMenu[i].id+"' class='footL1a' href='"+footMenu[i].url+"'>"+footMenu[i].title+"</a>";	
			if(footMenu[i].L2.length > 0){	
				menuString+="<ul class='footerL2'>";
				for(var j = 0; j < footMenu[i].L2.length; j++){				
					menuString+="<li><a href='"+footMenu[i].L2[j].url+"'>"+footMenu[i].L2[j].title+"</a></li>";		
					}				
				menuString+="</ul>";				
			}		
			menuString+="</li>";			
		}
		$("#footL1").append(menuString);
	});
	
	if(pdGlobal.currentPages[pdGlobal.currentPageLevel-1] != undefined){
		if(pdGlobal.currentPages[pdGlobal.currentPageLevel-1].type == "content"){
			$("#lInTblLCell").css("display","none");
		}
		
		if(pdGlobal.currentPages[pdGlobal.currentPageLevel-1].id === 120228){
			//$("#admissions_hpPhotoArea").css("display","block");
			//$("#L1 li a").height("39px");
			//$("#lInTblRCell").css("padding-top","20px");
			//$("#lInTblRCell").css("background","url(/ftpimages/81/podium/style185/images/admissions/hpTopFade.png) top no-repeat");
			willow.getPhotos(24812, willow.hpPhotos);
			willow.hpTitleLinks($(".cchhdrtxt-12499"));
			willow.hpTitleLinks($(".cchhdrtxt-12515"));
			$("#lOutTbl").css("padding-left","40px");
			$("#lOutTbl").css("padding-right","40px");
			
		}
		else{
			if(pdGlobal.currentPageLevel === 2){
				//$("#lInTblRCell").css({"padding-top":"20px","background":"url(/ftpimages/81/podium/style185/images/admissions/pageTopFade.png) top no-repeat"});					
			}
			
			if(pdGlobal.currentPageLevel === 3 && typeof pdGlobal.currentPages[1].id != "undefined" && pdGlobal.currentPages[1].id === 120228){
				$("#L1 li a").height("39px");
			}
		}
		if(pdGlobal.currentPages[pdGlobal.currentPageLevel-1].id === 204){
		$("#lInTblLCell").css("display","none");
		}
	}

	willow.getText(71978,function(data){
		$("#leftText").append(data.body);
	});
		
	willow.pageTitles($(".cchhdrtxt"));
	willow.pageTitles($(".cchhdrtxt-12507"));
	willow.pageTitles($(".cchhdrtxt-12517"));
	willow.pageTitles($(".ptl1"));
	willow.pageTitles($(".ptl2"));
	
	willow.hpTitleLinks($(".cchhdrtxt-12861"));
	willow.hpTitleLinks($(".cchhdrtxt-12862"));
	
	var date = new Date();
	$("#copyWrite").html("&copy; Worcester Academy "+date.getUTCFullYear());
	
	willow.addThisCode();
	
	willow.smButtons($("#icon_area"),19867);

	var $photoRotator = $(".photo-rotator");
	if($photoRotator.length > 0){
		willow.loadPhotoRotators($photoRotator);
	}
	
	
});

/*==== photo rotators code ====*/
willow.loadPhotoRotators = function($pr){
	var rotatorCount = 0;

	$pr.each(function(){
		var $obj = $(this),
			photoid = $obj.html(),
			newid = $obj.attr("groupid"),
			pwidth = parseInt($obj.attr("w")),
			pheight = parseInt($obj.attr("h")),
			gallerySelector = "photo_rotator_" + rotatorCount + "_";

		if(typeof newid !== "undefined"){
			photoid = newid;
		}

		gallerySelector += photoid;
		$obj.height(pheight).width(pwidth).attr("id",gallerySelector);

		if(photoid.length > 0){
			willow.getPhotos(photoid,function(data){
				var p = data.photo.images, output = "", iwidth = "", iheight=  "";;
				if(p.length > 0){
					output += "<div class='photo-holder'>"
					for (var i = 0; i < p.length; i++) {
						iwidth = "", iheight=  "";
						if(pwidth > 0){ iwidth = 'width="'+pwidth+'" '; }
						if(pheight > 0){ iheight = 'height="'+pheight+'" '; }
						output += '<img '+iwidth+iheight+'src="http://cdn.media78.whipplehill.net'+p[i].path+'" border="0"/>';
					};
					output += "</div>";
					output += "<ul class='gallery-nav'>";
					output += "<li><a href='#' class='prev'>previous</a></li>";
					output += "<li><a href='#' class='next'>next</a></li>";
					output += "</ul>";
					$obj.html(output);

					var $rotator = $obj.children(".photo-holder");
					$rotator.children("img").eq(0).show();
					setTimeout(function(){
						$rotator.fadeIn(250,function(){
							$(this).cycle({next:'#'+gallerySelector+' .next',prev:'#'+gallerySelector+' .prev'}).next().fadeIn(250);

						});
					},1500);
				}
			});
		}
		rotatorCount++;
	});
}





willow.hpTitleLinks = function($obj){	
	for(var i = 0; i < $obj.length; i++){
		var hpChannelInfo = $obj.eq(i).html().split(",");
		$obj.eq(i).html("<a class='hpLinkHeader' href="+willow.getPodiumURL2(hpChannelInfo[1])+">"+hpChannelInfo[0]+"</a>");
	}	
}
willow.getPodiumURL2 = function(id){
	id = parseInt(id);
	for(var i = 0; i < pdGlobal.customUrls.length; i++){
		if(id === pdGlobal.customUrls[i].id){
			return pdGlobal.customUrls[i].url;
		}
	}
	return "/podium/default.aspx?t="+id;
}
willow.pageTitles = function($obj){
	if($obj.length > 0){
		$obj.flash({
			swf: '/flash/pageTitle.swf',
			width: $obj.width(),
			height: $obj.height(),
			id: "splashPageTitle-swf",
			params:{wmode:'transparent'},
			flashvars: {
				titleL1: $obj.html(),
				callback: "flash_pt_size",
				id: "splashPageTitle-swf"
			}
		});
	}
}

willow.hpPhotos = function(data){
	if(data.photo.images){
		var photoString = "";
		for(var i = 0; i < data.photo.images.length; i++){	
			photoString += "<img id='photoNum_"+i+"' src='"+data.photo.images[i].path+"' height='300' width='1050' border='0'/>"
		}
		$("#admissions_hpPhotoArea").html(photoString).cycle({pause: 1, random: 1});
	} 
	else {
		$('#admissions_hpPhotoArea img').attr("src","/ftpimages/81/podium/style185/images/admissions/photo.jpg");
	}
}

willow.addThisCode = function(){
	
	var addthisstring = '<table padding="0" border="0px" cellspacing="0" width="350px"><tbody><tr><td colspan="2" align="center"><!--<br style="line-height:0px" mce_style="line-height:0px">--><div style="color:white; font-family:Arial, Times New Roman; font-size:18px; margin-top:5px"><b><!--ENCOURAGE FRIENDS TO DONATE-->Encourage Friends to Donate</b></div> </td></tr><tr><td colspan="2"><br style="line-height:75%" /><div style="font-family:lucida grande,tahoma,verdana,arial,sans-serif; font-size:17px; text-align:center; font-weight:bold; color:	#910533; margin-top:-5px">Share your generosity using:</div> </td></tr><tr><td style="font-family: Arial, Times New Roman; font-weight:bold; font-size: 13px; color: #910533;" align="center" width="115px"><img src="/images/Logo.gif" height="50px" /><br /> ANNUAL FUND</td><td><!-- AddThis Button BEGIN --><div class="addthis_toolbox addthis_default_style addthis_32x32_style"><div style="color:black; font-family:lucida grande,tahoma,verdana,arial,sans-serif; font-size:17px;"><table style="padding:0px;" cellspacing="10px"><tbody><tr><td><a addthis:description="Through your continued support we are able to instill in our students the desire to learn throughout life, to engage passionately with the world around them, and to be honorable persons of strong and resourceful character. Thank you for supporting Worcester Academy!" addthis:title="I donated to Worcester Academy!" addthis:url="http://www.worcesteracademy.org/givenow" class="addthis_button_facebook" style="TEXT-DECORATION: NONE; font-size:14px;">&nbsp;Facebook</a></td> <td><a addthis:title="I donated to Worcester Academy to instill in students the desire to learn and be honorable persons of strong character." addthis:url="http://www.worcesteracademy.org/givenow" class="addthis_button_twitter" style="TEXT-DECORATION: NONE; font-size:14px;">&nbsp;Twitter</a></td> 	</tr><tr><td><a addthis:description="Through your continued support we are able to instill in our students the desire to learn throughout life, to engage passionately with the world around them, and to be honorable persons of strong and resourceful character. Thank you for supporting Worcester Academy!" addthis:title="I donated to Worcester Academy!" addthis:url="http://www.worcesteracademy.org/givenow" class="addthis_button_linkedin" style="TEXT-DECORATION: NONE; font-size:14px;">&nbsp;LinkedIn</a></td> 	<td><a addthis:description="Through your continued support we are able to instill in our students the desire to learn throughout life, to engage passionately with the world around them, and to be honorable persons of strong and resourceful character. Thank you for supporting Worcester Academy!" addthis:title="I donated to Worcester Academy!" addthis:url="http://www.worcesteracademy.org/givenow" class="addthis_button_email" style="TEXT-DECORATION: NONE; color:blue; font-size:14px;">&nbsp;Email</a></td> </tr></tbody></table></div></div></td></tr></tbody></table>'; 

	$("#give-now-share").html(addthisstring);
	willow.givenowMetaTags();
}

willow.givenowMetaTags = function(){
	var meta = '<meta property="og:title" content="I donated to Worcester Academy!" />';
		meta += '<meta property="og:type" content="school" /> ';
		meta += '<meta property="og:url" content="https://www.worcesteracademy.org/givenow" /> ';
		meta += '<meta property="og:image" content="http://upload.wikimedia.org/wikipedia/en/d/d5/Crest1forwiki.png" />'; 
		meta += '<meta property="og:description" content="Through your continued support we are able to instill in our students the desire to learn throughout life, to engage passionately with the world around them, and to be honorable persons of strong and resourceful character. Thank you for supporting Worcester Academy!" /> ';
		meta += '<meta property="og:site_name" content="Worcester Academy." /> ';
		
	$("#PageHead").append(meta);
}

willow.smButtons = function($obj,id){
    willow.getLinks(id,function(data){
        var links = data.link;
        if(links.length === 0){return;}
        var lstring = "<ul id='icons'>";
        for(var i = 0; i < links.length; i++){
            lstring += "<li><a href='"+links[i].url+"'" + ((links[i].target == "true") ? " target='_blank'" : "") + ">"+
            ((typeof links[i].image !== "undefined") ? "<img src='"+links[i].image.path+"' border='0'/>" : links[i].title)+"</a></li>";
        }
        lstring += "</ul>";
        $obj.html(lstring);
    });
}


