// JavaScript Document
$(document).ready(function(){ 
		ge.ui.showMenu();
		ge.ui.createBanners();
		
		ge.ui.slideShow();
		$('#ge_txtSearch').focus(function(){ 
			if($.trim($(this).val())!=ge.ui.options.defaultText){
				return false;
			} else {
				$(this).val("");
			}
		})
		
		// blur
		$('#ge_txtSearch').blur(function(){ 
			if($.trim($(this).val())!=ge.ui.options.defaultText && $.trim($(this).val()).length <=0 ){
				$(this).val(ge.ui.options.defaultText);
			} else {
				return false;
			}
		})
		// highlight menu
		ge.ui.highlightMenu();
		ge.ui.options.logo = $('li','#logo_container');
		// logo
		ge.ui.scrollLogo();
		
		//popup
		$('.videoOverlay, .videoOverlay2, .videoOverlay3').click(function(e){
						e.preventDefault();
						url = $(this).attr('href');
					    wname = type = $(this).attr('name').toString();
				window.open('play_video.php?type='+type,wname,"width=400,height=400,menubar=no,status=no");
		})
});

var ge = {};
ge.ui = {
	options : {
		banners : ["banner1_v1.jpg","banner2_v1.jpg","banner3_v1.jpg","banner4_v2.jpg","banner5_v1.jpg","banner6_v2.jpg","banner7_v1.jpg"],
		imageBase : 'wp-content/images/',
		currentBanner : -1,
		selectedBanner : -1,
		items : [] ,
		defaultText : 'Search',
		timer : "",
		navigator : -1,
		cLogo : -1,
		sLogo : -1,
		delay : 10000
	},
	menu : {
		home : "",
		aboutus : ["22","25","27","29","31"],
		gec: ["33","35","37"],
		certified : ["43"],
		partners : ["582", "45","47","49"],
		media : ["472","514"],
		contactus : ["53"]
	},
	showMenu:function(){
		$('li','#ge_menuContainer').hover(
			function(){ $(this).addClass('activeMenu').find('ul').fadeIn(400); },
			function(){ $(this).removeClass('activeMenu').find('ul').fadeOut(200); }
		);
	}, // end show menu
	
	createBanners:function(){
		bannerObj = $(document.createElement('ul')); 
		imgNav = $(document.createElement('div'));
		for(var i=0;i<ge.ui.options.banners.length;i++){ 
			bannerObj.append( $('<li>').append(
				$('<div class="ge_bannerImg">').css('background-image','url('+ge.ui.options.imageBase+ge.ui.options.banners[i]+')')
			))
			imgNav.append( $('<a href="javascript:;"></a>').attr("image",ge.ui.options.banners[i]).html(i+1).bind("click",
						function(){  ge.ui.handleClick($(this).attr("image")) })
			) // appended img nav
		}
		imgNav.appendTo('#image-bar');
		bannerObj.appendTo('#ge_banner');
		ge.ui.options.items = bannerObj.children();
		ge.ui.options.navigator = $('div','#image-bar').children();
	},
	slideShow:function(){ 
		if((ge.ui.options.currentBanner < 0) || ( ge.ui.options.currentBanner >= ge.ui.options.banners.length)){ 
			ge.ui.options.selectedBanner = ge.ui.options.currentBanner;
			if(ge.ui.options.selectedBanner < 0){
				ge.ui.options.selectedBanner = 0;
			} else if(ge.ui.options.selectedBanner >= ge.ui.options.banners.length ) {
				ge.ui.options.selectedBanner = ge.ui.options.banners.length -1;
			}
			ge.ui.options.currentBanner = 0;
		} // end if
		$(ge.ui.options.items[ge.ui.options.selectedBanner]).fadeOut("fast",function(){
				$(ge.ui.options.items[ge.ui.options.currentBanner]).fadeIn(1100,function(){ 
				ge.ui.options.selectedBanner=ge.ui.options.currentBanner;
				ge.ui.options.currentBanner++;
				ge.ui.options.timer = setTimeout(ge.ui.slideShow,ge.ui.options.delay);
			})
		}) // end banner fade in
		$(ge.ui.options.navigator[ge.ui.options.selectedBanner]).removeClass('highlighted')
		$(ge.ui.options.navigator[ge.ui.options.currentBanner]).addClass('highlighted')
	}, // end function slide show
	
	// function to highlight 
	highlightMenu:function(){
		page_id = ge.ui.getQuerystring('page_id',"");
		key = ge.ui.getKey(page_id);
		switch(key){ 
			case 'aboutus':
			case 'gec':
				$('#'+key).addClass("highlight");
			break;
			case 'certified': 
				$('#'+key).addClass("highlight");
			break;
			case 'partners':
				$('#'+key).addClass("highlight");
			break;
			case 'media':
				$('#'+key).addClass("highlight");
			break;
			case 'contactus':
				$('#'+key).addClass("highlight");
			break;
			default: 
				$('#home').addClass("highlight");
			break;
		}
	},
	getKey:function(curr_page){ 
		for(var i in ge.ui.menu){
			for(var j in ge.ui.menu[i]){
				if(curr_page == ge.ui.menu[i][j]){
					return i;
				}
			}
		}
	},
	getQuerystring:function(key, default_)
	{
	  if (default_==null) default_="";
	  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
	  var qs = regex.exec(window.location.href);
	  if(qs == null)
		return default_;
	  else
		return qs[1];
	},
	scrollLogo:function(){ 
		if((ge.ui.options.cLogo < 0) || ( ge.ui.options.cLogo >= ge.ui.options.logo.length)){ 
			ge.ui.options.sLogo = ge.ui.options.cLogo;
			if(ge.ui.options.sLogo < 0){ 
				ge.ui.options.sLogo = 0;
			} else if(ge.ui.options.sLogo >= ge.ui.options.logo.length ) { 
				ge.ui.options.sLogo = ge.ui.options.logo.length -1;
			}
			ge.ui.options.cLogo = 0;
		} // end if
		$(ge.ui.options.logo[ge.ui.options.sLogo]).fadeOut("fast",function(){
				$(ge.ui.options.logo[ge.ui.options.cLogo]).fadeIn(1100,function(){  
				ge.ui.options.sLogo=ge.ui.options.cLogo;
				ge.ui.options.cLogo++;
				setTimeout(ge.ui.scrollLogo,ge.ui.options.delay);
			})
		}) // end banner fade in
	},
	handleClick:function(sel_image){  
		ge.ui.options.navigator.each(function(){  
			$(this).unbind();
		})
		clearTimeout(ge.ui.options.timer);
		ge.ui.options.currentBanner = ge.ui.getIndex(sel_image);
		
		$(ge.ui.options.items[ge.ui.options.selectedBanner]).fadeOut("fast",function(){
				$(ge.ui.options.items[ge.ui.options.currentBanner]).fadeIn(1100,function(){ 
				ge.ui.options.selectedBanner=ge.ui.options.currentBanner;
				ge.ui.options.currentBanner++;
				ge.ui.options.navigator.each(function(){  
					$(this).bind("click",function(){ ge.ui.handleClick($(this).attr("image")) });
				})
			})
		}) // end banner fade in
		$(ge.ui.options.navigator[ge.ui.options.selectedBanner]).removeClass('highlighted')
		$(ge.ui.options.navigator[ge.ui.options.currentBanner]).addClass('highlighted')
	},
	
  getIndex:function(sel_image) {
		var myPosition=-1
		for (i=0;i<ge.ui.options.banners.length;i++) {
			if(ge.ui.options.banners[i]==sel_image) {
				myPosition = i;
				break;
			}
		}
		return myPosition;
  }
}

if(document.images){

banner1 = new Image(900,260);
banner1.src = "wp-content/images/banner1_v1.jpg";

banner2 = new Image(900,260);
banner2.src = "wp-content/images/banner2_v1.jpg";

banner3 = new Image(900,260);
banner3.src = "wp-content/images/banner3_v1.jpg";


banner4 = new Image(900,260);
banner4.src = "wp-content/images/banner4_v2.jpg";

banner5 = new Image(900,260);
banner5.src = "wp-content/images/banner5_v1.jpg";

banner6 = new Image(900,260);
banner6.src = "wp-content/images/banner6_v2.jpg";


banner7 = new Image(900,260);
banner7.src = "wp-content/images/banner7_v1.jpg";


menubg = new Image(86,30);
menubg.src = "wp-content/images/menu-bg.jpg";

menutop = new Image(278,13);
menutop.src = "wp-content/images/menu-top.jpg";

menutop = new Image(278,13);
menutop.src = "wp-content/images/menu-bottom.jpg";

ey = new Image(200,200);
ey.src = "wp-content/images/ey.jpg";

bain = new Image(200,200);
bain.src = "wp-content/images/bain_1.0.png";

bbdo = new Image(200,200);
bbdo.src = "wp-content/images/bbdo.png";

hed = new Image(200,200);
hed.src = "wp-content/images/heidrick.png";

gebg = new Image(278,13);
menutop.src = "wp-content/images/ge_bg.jpg"; 

bannerinner = new Image(900,260);
bannerinner.src = "wp-content/images/eves.jpg";

}


