var menuSettings = new Array(
	{pageid : 114061,hoffset:0,voffset:0},
	{pageid : 114068,hoffset:0,voffset:0},
	{pageid : 114096,hoffset:0,voffset:0},
	{pageid : 114104,hoffset:0,voffset:0},
	{pageid : 114114,hoffset:0,voffset:0},
	{pageid : 114128,hoffset:0,voffset:0}
);
var options = {
    direction:"down",
    settings:menuSettings,
	showL3s:false,
	currentL1:pdGlobal.currentPages[0].id
};

var linkOptions = {
    linkImage:1
};

willow.ready(function($) {
     willow.getMenu("114061|114068|114096|114104|114114|114128",function(data){
   	$('#nav-down').menu(data.menu,options);
	$("#buttonNav").writeLinks(linkOptions);
     }); 	
});

//Check for added variable to podium url
function getQueryVariable(variable) {
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	for (var i=0;i<vars.length;i++) {
		var pair = vars[i].split("=");
		if (pair[0] == variable) {
			return pair[1];
		}
	} 
	return -100;
}

//START for debug/log stuff
jQuery.log = function(message) {
 if(window.console && $.browser.mozilla) {
    console.debug(message);
 }
};
//$.log("some message !");
//END for debug/log stuff

var loadPhotos = true;

$.ajax({
	type: "GET",
    url: "/xml_files/list_xml.asp?listID=2867",
    dataType: "xml",
    success: function(xml) {
    	$(xml).find('list').each(function(){
    		//alert(parseInt(pdGlobal.currentPages[pdGlobal.currentPages.length-1].id) +" : "+ parseInt($(this).find("brief").text()));
    		if(parseInt(pdGlobal.currentPages[pdGlobal.currentPages.length-1].id) == parseInt($(this).find("brief").text())){
    			//alert("found one");
    			loadPhotos = false;
    		}
    	});
		
    },
    error: function(request,tStatus,eThrown){
    }
});

if(loadPhotos){	
	//check list group for custom photo on this page
	$.ajax({
		type: "POST",//CAS98658 sdb 110309 was GET, IE would skip the call periodically
		url: "/xml_files/list_xml.asp?listID=2947",
		dataType: "xml",
		success: function(xml) {
			//alert("called list");
			$(xml).find('list').each(function(){
				//alert(parseInt(pdGlobal.currentPages[pdGlobal.currentPageLevel-1].id + " : " + parseInt($(this).find("brief").text())));			   
			   if(pdGlobal.currentPages[pdGlobal.currentPageLevel-1].id == $(this).find("brief").text()){
			    	//alert("found a page");
			    	//set my photo
			    	var path = $(this).find("path").text();
					var title = $(this).find("title").text();
					var bannerid = $(this).find("bannerid").text();
					$("#photo").css("background","url("+path+") no-repeat");
					$("#photo-container").removeClass("collapsed");
					//$.log(bannerid)
			  	  	loadPhotos = false;
			    }
			    	
			});
			
		},
		error: function(request,tStatus,eThrown){
			//alert("List Group Error");
		}
	});
}

$(document).ready(function() {
  switch(pdGlobal.currentPages[0].id){
  	case 114061: turnOn(1); GetPhotos(25623,loadPhotos); break;
  	case 114068: turnOn(2); GetPhotos(25624,loadPhotos); break;
  	case 114096: turnOn(3); GetPhotos(25626,loadPhotos); break;
  	case 114104: turnOn(4); GetPhotos(25627,loadPhotos); break;
  	case 114114: turnOn(5); GetPhotos(25628,loadPhotos); break;
  	case 114128: turnOn(6); GetPhotos(25629,loadPhotos); break;
  	case 114139: turnOn(7); GetPhotos(25630,loadPhotos); break;
  	case 114166: turnOnOmni(1); GetPhotos(25632,loadPhotos); break;
  	case 114158: turnOnOmni(2); GetPhotos(25631,loadPhotos); break;
  } 
  
  if(pdGlobal.currentPages[0].type == "portal"){
  	$("#omni_t3").addClass("on");
  }
  
  switch(pdGlobal.currentPages[0].id){
  	case 114061: $("#title-container").css("background-image","url(/ftpimages/97/podium/style469/pt_orange.png)"); break;
  	case 114068: $("#title-container").css("background-image","url(/ftpimages/97/podium/style469/pt_green.png)"); break;
  	case 114096: $("#title-container").css("background-image","url(/ftpimages/97/podium/style469/pt_purple.png)"); break;
  	case 114104: $("#title-container").css("background-image","url(/ftpimages/97/podium/style469/pt_blue.png)"); break;
  	case 114114: $("#title-container").css("background-image","url(/ftpimages/97/podium/style469/pt_green.png)"); break;
  	case 114128: $("#title-container").css("background-image","url(/ftpimages/97/podium/style469/pt_blue.png)"); break;
  	case 114139: $("#title-container").css("background-image","url(/ftpimages/97/podium/style469/pt_orange.png)"); break;
  	case 114166: $("#title-container").css("background-image","url(/ftpimages/97/podium/style469/pt_green.png)"); break;
  	case 114158: $("#title-container").css("background-image","url(/ftpimages/97/podium/style469/pt_orange.png)"); break;
  	case 115735: $("#title-container").css("background-image","url(/ftpimages/97/podium/style469/pt_yellow.png)"); break;
  	case 115736: $("#title-container").css("background-image","url(/ftpimages/97/podium/style469/pt_yellow.png)"); break;
  	default: $("#title-container").css("background-image","url(/ftpimages/97/podium/style469/pt_green.png)"); break;
  }
  $("#page-title").html(pdGlobal.currentPages[pdGlobal.currentPageLevel-1].title); 
  
  if(pdGlobal.currentPages[0].id == 116136){
  	$(".sitelcol").css("display","none");
  	$(".sitepg").css({"width":"970px","padding-left":"138px"});
	$(".sitepg").css("background-image","url(/ftpimages/97/podium/style469/blog_left_bg.gif)");
	$(".sitepg").css("background-repeat","repeat-x");
	$(".sitepg").css("background-color","#333835");
  	$("#eng").css("width","970px");
  	$("#if"+pdGlobal.currentPages[1].id).css("width","965px");
  }
  
	//pulling in footer buttons using pack.writeLinks.js, see jquery.json.writeLinks.js for unpacked version
	$("#left_links").writeLinks({linkImage: 1,hardPhotoWidth: 169});
});

function turnOn(num){
	$("#L1_"+num).addClass("on");
}
function turnOnOmni(num){
	$("#omni_t"+num).addClass("on");
}
function CheckList(lID){
	var returnValue = true;
		
}
function GetPhotos(pID,lphotos){	
	$.ajax({
		type: "GET",
		url: "/xml_files/photo_allAlbums_xml.asp?photoGroupID="+pID,
		dataType: "xml",
		success: function(xml) {
			//alert(pID);
			if(lphotos){
				var totalphotos = parseInt($(xml).find('group').attr("totalphotos"));
				var randomNum = Math.floor(Math.random() * (totalphotos+1));
				var randCount = 0;
				$(xml).find('photo').each(function(){
					if(randCount == randomNum){
						//set my photo
						var path = $(this).find("path").text();
						
						$("#photo").css("background","url("+path+") no-repeat");
						$("#photo-container").removeClass("collapsed");
					}
					randCount++;
				});
			}
		},
		error: function(request,tStatus,eThrown){
			//alert("Cant Get Photos");
		}
	});		
}
