willow.fixPodiumNav();

var bannerPhotoID = 0;

switch(pdGlobal.currentPages[0].id){
	case 139252: bannerPhotoID = 39266; break; //About AHN
	case 139253: bannerPhotoID = 39267; break; //Admissions
	case 139254: bannerPhotoID = 39268; break; //Academics
	case 139255: bannerPhotoID = 39269; break; //School Life
	case 139256: bannerPhotoID = 39270; break; //Supporting AHN
	default: bannerPhotoID = 39271; break; //Portal-Application
}

willow.ready(function($){

	var $sitemap = $(".sitemap");

	var menuOptions = {
		direction:"down",
		showL3s:false,
		currentL1:pdGlobal.currentPages[0].id
	};

	willow.getMenu("139252|139253|139254|139255|139256",function(data){
		$('#L1').menu(data.menu,menuOptions);
		
		if($sitemap.length > 0){
			$sitemap.sitemap(data);
			//uncomment this if you want to expand all by default$("#expand").click();
		}
	});

	var emOptions = {
		emButtonPosition: "right",
		emButton: false
	};

	willow.getNews("13256",function(data){$('#Form1').bulletin(data,emOptions);},{"backlink":window.location});
	
	if(pdGlobal.currentPages[pdGlobal.currentPageLevel-1].type == "portal" || pdGlobal.currentPages[pdGlobal.currentPageLevel-1].type == "application"){
		$("#bannerPhoto").css("display","none");
	}
	if($("#lNavPhoto img").length === 0){
		$("#lNavPhoto").css("border","0");
	}
	
	var L2title = $(".ptl2").html();
	$(".ptl2").html("<span>"+L2title+"</span>");
	var L3title = $(".ptl3").html();
	$(".ptl3").html("<span>"+L3title+"</span>");
	
	willow.interiorPhotos($("#bannerPhoto img"), bannerPhotoID);

//homepage settings
if(pdGlobal.currentPages[0] !== undefined){
	if(pdGlobal.currentPages[0].id == 139257){
		willow.getText(76865, function(data){			
			if(data.body.length > 0){				
				willow.homepageContent(true);
			}
			else{
				willow.homepageContent(false);
			}			
		});
		//$('body').addClass("homepage");
	};
}
	//if no login box and/or user nav, hide nav separator
	if($("#L_c4i0").length < 1){
		$("#lNavSep").css("height","0");
	}
});	

willow.homepageContent = function(boolean){
	if(boolean === true){
		willow.elementDisplay($("#lNavTop"), false);
		willow.elementDisplay($("#lNavPhoto"), false);
		willow.elementDisplay($("#L_c4i0"), false);
		willow.elementDisplay($("#lNavSep"), false);
		willow.elementDisplay($("#L_c5i0"), false);
		$("#contactUs a").css("margin-left","25px");
		$("#lInTbl").css("background-image","url(/ftpimages/487/podium/style603/images/hpContentFooter.png)").css("padding-top","0");
		$("#lInTblLCell").css("padding-left","19px");
		$("#footer").css("background","url(/ftpimages/487/podium/style603/images/homepageBottomFade.png) no-repeat").css("height","55px");
		$("#footer address").css("margin-top","17px");
		$("#contactUs a").css("margin-top","14px");
		willow.hpButtons($(".hpLeftColButtons"), 16006);
		willow.hpText($(".hpLeftColText"), $(".textTitle"), $(".textBody"), 76886, $(".textPhoto img"));
		willow.hpNews($(".hpLeftColNews"), $(".newsTitle"), $(".newsDetail"), $(".readMore a"), 13347);
		$(".ptWrap").css("display","none");
	}
	else{
		willow.elementDisplay($("#lInTbl"), false);		
		$("#homepagePhoto").css("background-image","url(/ftpimages/487/podium/style603/images/homepagePhotoBG_noContent.png)");
	}
	willow.elementDisplay($("#bannerPhoto"), false);
	willow.hpPhotos($("#homepagePhoto"), 38611);
	willow.elementDisplay($("#interiorLatinLink"), false);
	willow.elementDisplay($("#homepagePhoto"), true);
	willow.elementDisplay($("#homepageLatinLink"), true);
	$("#contactUs a").css("margin-left","25px");
}

willow.elementDisplay = function($obj, boolean){
	if(boolean === true){
		$obj.css("display","block");
	}
	else{
		$obj.css("display","none");
	}
}

willow.interiorPhotos = function($obj,interiorId){
	willow.getPhotos(interiorId,function(data){
		if(data.photo.images.length === 0){
			$obj.attr("src","/ftpimages/487/podium/style603/images/defaultBannerPhoto.jpg");
			return;
		}
		$obj.attr("src",data.photo.images[0].path);
	});
}	

willow.hpPhotos = function($obj,HPid){
	willow.getPhotos(HPid,function(data){
		if(data.photo.images.length === 0){
			$obj.children().attr("src","/ftpimages/487/podium/style603/images/defaultHomepagePhoto.jpg").css("margin-left","17px");
			$("#lInTblLCell").css("padding-left","17px");
			return;
		}
		var photoString = "";		
		for(var i = 0; i < data.photo.images.length; i++){
			photoString += "<img src='"+data.photo.images[i].path+"' height='"+data.photo.images[i].height+"' width='"+data.photo.images[i].width+"'border='0'/>";
		}
		$obj.html(photoString);
		$obj.cycle({pause: 1});
	});
}

willow.hpText = function($obj, $title, $body, textId, $photo){
	willow.getText(textId,function(data){
		if(data.body.length === 0){return;}	
		//$title.html(data.desc); 2/2/2011 commented out KAQ.
		$body.html(data.body.replace(/&quot;/gi, "'"));
		if(data.images.length > 0){ // 7/12/11 added check to make sure there is a photo in the text group -KAQ
			$("#textPhoto").css("display","block");
			$photo.attr("src",data.images[0].path);
		}
		willow.elementDisplay($obj, true);
	});
}

willow.hpNews = function($obj, $title, $detail, $readMore, hpNewsid){
	willow.getNews(hpNewsid,function(data){
		if(data.news.length === 0){return};
		$title.html(data.news[0].title);
		$detail.html(data.news[0].brief);
		$readMore.attr("href",data.news[0].url);
		willow.elementDisplay($obj, true);
	});		
}

willow.hpButtons = function($obj,hpButtonId){
	willow.getLinks(hpButtonId,function(data){
		var links = data.link;
		if(links.length === 0){return;}
		var lstring = "";
		for(var i = 0; i < links.length; i++){
			lstring += "<div class='lcButton'>"
			lstring += "<a href='"+links[i].url+"'" + willow.checkTarget(links[i].target) + ">"+
			((typeof links[i].image !== "undefined") ? "<img src='"+links[i].image.path+"' height='"+links[i].image.height+"' width='"+links[i].image.width+"'border='0'/>" : links[i].title)+"</a>";
			lstring += "</div>";
		}		
		$obj.html(lstring);
		willow.elementDisplay($obj, true);
	});
}

willow.checkTarget = function(target){
	if(target == 1 || target == true || target == "true"){
		return " target='_blank'";
	}
	return "";
};

