var lastOpen = null;
var timers = new Object();
var timeout = 300;
var lastId;
var downId;

$(document).ready(function(){
	
	var scope = this;
	
	$('div.preview').hide();
	$('div.thumb-highlight').hide();
	var h = 0;
	$('div.preview').each(function(index,ele){
		$(this).css('top', 140+h);
		h += 40;
		var id = $(this).attr('id').substr(7);
		$(ele).mouseover(function(){
		  clearTimeout(timers[id]);
	    });	
		$(ele).mouseout(function(){
		  //alert($(this).attr('id'));
		  timers[id] = setTimeout('hidePreview("'+id+'")', timeout);
	    });	
		$(ele).click(function(){
		  //alert($(this).attr('id'));
		  hidePreview(id);
		  onMenuClick(id);
	    });
	});
	var divs = $('div.number-thumb');
	h = 0;
	divs.each(function(index,ele){
		var id = $(this).attr('id').substr(5);
		$(this).css('top', h);
		h += 40;
		$(ele).mouseover(function(){
		  //alert($(this).css('color'));
		  $(this).css('color', '#c7a03b');
		  if (lastId && lastId!=id) {
			  clearTimeout(timers[lastId]);
			  hidePreview(lastId);
		  }
		  lastId = id;
		  clearTimeout(timers[id]);
		  showPreview(id);		  
		  $('#hl'+id).show();
	    });	
		$(ele).mouseout(function(){
		  //alert($(this).attr('id'));
		  $(this).css('color', '#999999');
		  timers[id] = setTimeout('hidePreview("'+id+'")', timeout);
		  if (downId != id) {
			  $('#hl'+id).hide();
		  }	
	    });	
		$(ele).click(function(){
		  //alert($(this).attr('id'));
		  $(this).css('color', '#c7a03b');		  	  
		  hidePreview(id);
		  onMenuClick(id);
		  downId = id;
	    });
	})
	
	
	$('#switcher').click(function(){
		document.getElementById('website').setOmnitureTrackLink('trackLink=LORUS>home>grid','channel=home','prop14=LORUS>home>grid');
		
		if (String(location.hash).indexOf('main:home:thumbview')==-1) {
		   document.getElementById('website').navigate('top{userdata//d+d//|diagnostic|main:home:thumbview|media:_blank|nav|overlay:_blank}');
	   } else {
		   document.getElementById('website').navigate('top{userdata//d+d//|diagnostic|main:home:section6|media:_blank|nav|overlay:_blank}');
	   };  
	 });
	detectThumbView();
	detectButtonDown();
	
	if (String(location.hash).indexOf('main:home')==-1) {
		  $('#left-side-menu').hide();
	} 
	/*
	$(window).bind('hashchange', function() { 
	   onHashchange();
    }); 
	*/
		
	
})

function onHashchange() {
	//alert('hashchange '+String(location.hash));
	detectHomePage();
	detectThumbView();
	detectButtonDown();
}

function detectHomePage() {
	//alert('detectHomePag '+String(location.hash).indexOf('main:home'));
	   if (String(location.hash).indexOf('main:home')==-1) {
		   hideSideBar();
	   } else {
		   showSideBar();
	   };
}

function detectThumbView() {
	//alert('hashchange '+String(location.hash).indexOf('main:home'));
	    if (String(location.hash).indexOf('main:home:thumbview')==-1  ) {
           $('#grid_icon').show();
             $('#stack_icon').hide();
                   } 
				   else {
                                   $('#grid_icon').hide();
                                   $('#stack_icon').show();
                   };

}

function detectButtonDown() {
	//if (String(location.hash).indexOf('main:home')!=-1 && String(location.hash).indexOf('main:home:')==-1) {
	//	   $('#hl1').show();
	//	   downId = '1';
	 //  } else {
	//	   $('#hl1').hide();
//};
	for (var i=1; i<10; i++) {
		if (String(location.hash).indexOf('main:home:section'+i)==-1) {
		   $('#hl'+i).hide();
		   //alert("hide "+i);
	   } else {
		   $('#hl'+i).show();
		   downId = String(i);
	   };
	}
}

function onMenuClick(id) {
	//alert(document.getElementById('website'));
	//alert(id+' '+(id == '1'));
	document.getElementById('website').setOmnitureTrackLink('trackLink=LORUS>home>leftnav>hero'+id,'channel=home','prop14=LORUS>home>leftnav>hero'+id);
	//if (id == '1') {
	//	document.getElementById('website').navigate('top{userdata//d+d//|diagnostic|main:home|media:_blank|nav|overlay:_blank}');
	//} else {
		document.getElementById('website').navigate('top{userdata//d+d//|diagnostic|main:home:section'+id+'|media:_blank|nav|overlay:_blank}');
	//}
}


function hideSideBar() {
  //alert('hideSideBar '+String(location.hash));
  $('#left-side-menu').css('display', 'none');
  $('#left-side-menu').fadeOut('fast');
}

function showSideBar() {
  //alert('showSideBar '+String(location.hash));
  $('#left-side-menu').css('display', 'block');
  $('#left-side-menu').fadeIn('fast');
}

function showPreview(id) {
	//alert(id);
 $('#preview'+id).fadeIn('fast');
}

function hidePreview(id) {
 $('#preview'+id).fadeOut('fast');
}


function RedirectTo6(){
if (String(location.hash).indexOf('main:home|media:_blank')!=-1) {
 location="/_us/_en/default.aspx#/?page=top{userdata//d+d//|diagnostic|main:home:section6|media:_blank|nav|overlay:_blank}" 

         }
}


RedirectTo6();
     

