/*BEGIN: DROPDOWN MENU*/
/*var lis = null;
var IsTag1Shown = new Boolean(false);
var IsTag2Shown = new Boolean(false);
var IsTag3Shown = new Boolean(false);
var IsTag4Shown = new Boolean(false);
var IsTag5Shown = new Boolean(false);
var IsTag6Shown = new Boolean(false);
var IsTag7Shown = new Boolean(false);
var IsTag8Shown = new Boolean(false);
*/
/*END: DROPDOWN MENU*/
function handler(event) {
	event.data.foo.css("display","block");
}
/*CHECK IF APPROPRIATE FLASH PLAYER IS INSTALLED, IF NOT REDIRECT THE USER TO THE WEBSITE, WHERE THE NECCESSARY PLAYER IS AVAILABLE*/

function flashDetect(){
	var flash = $("object[data$='.swf']");
	
	if (flash!=null){		
		if(!FlashDetect.installed){
			flash.replaceWith("<div style='text-align:center;'>" +
					"<a target='_blank' href='http://get.adobe.com/flashplayer/'><img src='images/GGVideoAlt.gif'/></a>"+
				"</div>");
		}else{
			if (FlashDetect.major < 9){
					flash.replaceWith("<div style='text-align:center;'>"+
							"<a target='_blank' href='http://get.adobe.com/flashplayer/'><img src='images/GGVideoAlt.gif'/></a>"+
						"</div>");
			}
		}
    }

}
/*
EmbedSitePatch = function(){
	var object = $("iframe");	
	if(object != null){
		object.attr("height",object.get()[0].contentWindow.document.body.scrollHeight + "px");
		//object.appendTo("<div>test</div>");
		//<param name='wmode' value='transparent' />

	}
}
*/
function Initialization(){		
	
	l1s = $("#nav .L0").find(".L1");
	
	//Initialize menu	
	var tts = $("#nav .L0").find(".TopTag").each(function(i){
		$(this).addClass("tag"+(i+1).toString());
	});	
	
	delImmBlank();
	CalendarPatch();
	StylePickerPatch();
	LHNavigation();
	flashDetect();
	//EmbedSitePatch();
}
LHNavigation = function(){
	/*BEGIN: Left hand side navigation*/
	
	var ct2 = "LinkLevel";	
	var obj = $(".welcom-div .welcom-link-activate");
	var cs = obj.attr("class");	
	if(cs != null){
		var i = cs.indexOf(ct2);
		var ulvl = cs.substring(i+ct2.length,cs.length);
		
		if(obj.hasClass("hasChild")){
			$(".welcom-div .welcom-link").each(function(){
				var c = $(this).attr("class");
				var j = c.indexOf(ct2);
				var dlvl = c.substring(j+ct2.length,c.length);
				
				if ((dlvl - 1) == ulvl){$(this).addClass("HightLighted")}		
			});
		}else if(obj.hasClass("noChild")&&ulvl!="1"){
			$(".welcom-div .LinkLevel"+ulvl).addClass("HightLighted");
		}
	}
	
	/*END: Left hand side navigation*/	
}
CalendarPatch = function(){
	//Initialize Imm Calendar control
	$(".eventCalendar .eventDetailsHeaders a").each(function(){
		if($(this).attr("href").indexOf("mailto:")==-1){
			$(this).attr("target","_blank");
		}else{
			if ($(this).text().length!=0){$(this).text("Click here")};
		}
	});
	
	$(".eventCalendar .eventMonth").filter(function(index){
		if(index == 0){
			$(this).parent().addClass("event1stTR");
			return;
		}
	});

	$(".eventCalendar .eventFooter").parent()
		.addClass("eventKeyTR")
		.insertBefore(".event1stTR");
}

StylePickerPatch = function(){		
        if (document.cookie && document.cookie != '') {
			var cookieValue = null;
			var colourscheme = "colourscheme";
			var fontsize = "fontsize";
			var StylePicker = "StylePicker";			
            var cookies = document.cookie.split(';');
            
            for (var i = 0; i < cookies.length; i++) {
				var cookie = jQuery.trim(cookies[i]);
				//ignore those cookies that were not generated from StylePicker
				if(cookie.indexOf(StylePicker)==-1) continue;				
				//only find cookie named "colourscheme"
				if(cookie.indexOf(colourscheme)!=-1){				
					var index = cookie.indexOf("=");
					if(index != -1) {
						cookieValue = cookie.substring(index + 1,cookie.length);
						
						switch(cookieValue){
							case "BlackonYellow":
								$("body").css("background","#FFFF80");	
								break;												
							case "BlackonPalePink":
								$("body").css("background","#F9DDD6");	
								break;
							case "BlackonCream":
								$("body").css("background","#FAF7E2");	
								break;												
							case "BlackonPaleBlue":
								$("body").css("background","#C2D3FC");	
								break;
							case "YellowonBlack":
								$("body").css("background","#000");	
								break;
							case "BlueonYellow":
								$("body").css("background","#FFFF80");	
								break;
							default:
								break;														
						}
					}
					
					break;
				}                
            }
        }	
}

function delImmBlank(){
	/**/	
	$(".middle-data div.what-row").each(function(){
		var IsDel = new Boolean(true);
		$(this).find(".what-data").each(function(){
			if(jQuery.trim($(this).html()).length>0){
				IsDel=false;
			}
		});
		
		if(IsDel){$(this).css("display","none");}
	});
}

$(document).ready(function(){	
	Initialization();	
	
	
	
	$(".eventCalendar .eventMonthItem a").click(function(){
		$(".eventCalendar .eventMonthItem a").each(function(){
			$(this).css("background-color","#fff");
		});
		$(this).css("background-color","#EEEEEE");
	});	
	
	/*BEGIN: DROPDOWN MENU*/
	$("#topdropmenu .L0 li .L0hc").mouseover(function(){
		//make all tags to be invisiable first
		l1s.css("display","none");
		
		var L1 = $(this).next();
		var pra = $(this).parent();
		
		L1.css("display","block");
		/*
		if(pra.hasClass("tag1")){			
			IsTag1Shown=true;
			L1.fadeIn(300,function(){
				if(!IsTag1Shown){
					L1.css("display","none");
				}
			});
		}
		if(pra.hasClass("tag2")){
			IsTag2Shown=true;
			L1.fadeIn(300,function(){
				if(!IsTag2Shown){
					L1.css("display","none");
				}
			});
		}
		if(pra.hasClass("tag3")){
			IsTag3Shown=true;
			L1.fadeIn(300,function(){
				if(!IsTag3Shown){
					L1.css("display","none");
				}
			});
		}
		if(pra.hasClass("tag4")){
			IsTag4Shown=true;
			L1.fadeIn(300,function(){
				if(!IsTag4Shown){
					L1.css("display","none");					
				}
			});
		}
		
		if(pra.hasClass("tag5")){			
			IsTag5Shown=true;
			L1.fadeIn(300,function(){
				if(!IsTag5Shown){
					L1.css("display","none");
				}
			});
		}
		if(pra.hasClass("tag6")){
			IsTag6Shown=true;
			L1.fadeIn(300,function(){
				if(!IsTag6Shown){
					L1.css("display","none");
				}
			});
		}
		if(pra.hasClass("tag7")){
			IsTag7Shown=true;
			L1.fadeIn(300,function(){
				if(!IsTag7Shown){
					L1.css("display","none");
				}
			});
		}
		if(pra.hasClass("tag8")){
			IsTag8Shown=true;
			L1.fadeIn(300,function(){
				if(!IsTag8Shown){
					L1.css("display","none");					
				}
			});
		}
		*/
		//make the tag to be active
		$(this).addClass("active").find("span").addClass("active");
	}).mouseout(function(){		
		var pra = $(this).parent();
		/*
		if(pra.hasClass("tag1")){IsTag1Shown = false;}
		if(pra.hasClass("tag2")){IsTag2Shown = false;}
		if(pra.hasClass("tag3")){IsTag3Shown = false;}
		if(pra.hasClass("tag4")){IsTag4Shown = false;}
		if(pra.hasClass("tag5")){IsTag5Shown = false;}
		if(pra.hasClass("tag6")){IsTag6Shown = false;}
		if(pra.hasClass("tag7")){IsTag7Shown = false;}
		if(pra.hasClass("tag8")){IsTag8Shown = false;}*/
		var L1 = $(this).next();		
		(L1.css("display") == "block")?L1.css("display","none"):null;	
		$(this).removeClass("active").find("span").removeClass("active");
	});	
	
	$("#topdropmenu .L1").mouseover(function(){
		var par = $(this).parent();
		/*
		if(par.hasClass("tag1")){IsTag1Shown=true;}
		if(par.hasClass("tag2")){IsTag2Shown=true;}
		if(par.hasClass("tag3")){IsTag3Shown=true;}
		if(par.hasClass("tag4")){IsTag4Shown=true;}
		if(par.hasClass("tag5")){IsTag5Shown=true;}
		if(par.hasClass("tag6")){IsTag6Shown=true;}
		if(par.hasClass("tag7")){IsTag7Shown=true;}
		if(par.hasClass("tag8")){IsTag8Shown=true;}*/
		var L1 = $(this);
		(L1.css("display") == "none")?L1.css("display","block"):null;		
		
		L1.prev().addClass("active").find("span").addClass("active");		
	}).mouseout(function(){
		var L1 = $(this);
		(L1.css("display") == "block")?L1.css("display","none"):null;
		
		var ahc = L1.prev();
		ahc.removeClass("active").find("span").removeClass("active");
	});	
	/*END: DROPDOWN MENU*/
	
	
	// incident 22177 - GG button need to be change
	$(".mini-box").mouseover(function(){	
		$(this).find(".mini-box-text").css("background-color", "#0076bc");
		$(this).css("cursor","pointer");
		$(this).find("img:first").attr("src","images/template/new/box-top-page2.jpg");
		$(this).find("img:last").attr("src","images/template/new/box-bottom-page2.jpg");
	}).mouseout(function(){
		$(this).find(".mini-box-text").css("background-color", "#61B0DF");
		$(this).find("img:first").attr("src","images/boxlight-top-page2.jpg");
		$(this).find("img:last").attr("src","images/boxlight-bottom-page2.jpg");
	});
	
	//toolkit zone aims-actions-impact
	var imgRest = '_rest';
	var imgRoll = '_roll';
	$(".AimsActionImpactTable").attr("cellSpacing","0").attr("cellPadding","0").css("margin","0 auto");
	$(".AimsActionImpactTable img").mouseover(function(	){
		$(this).attr("src",$(this).attr("src").replace(imgRest,imgRoll));
	}).mouseout(function(){
		$(this).attr("src",$(this).attr("src").replace(imgRoll,imgRest));
	});	
	
	$(".go-link:input").mouseover(function(){
		$(this).addClass("go-link-over");
	}).mouseout(function(){
		$(this).removeClass("go-link-over");
	});
	
	
	
	
});

