/* jquery  for hierarchy */
var lastLi1; var lastLi2; var lastLi3; 
var ulsc1; var ulsc2; var ulsc3; 

var currLi1; var currLi2; var currLi3; 



function makeScrollable(){
	var div1 = $('div.sc_menu1'); var div2 = $('div.sc_menu2');
	var div3 = $('div.sc_menu3'); 
	ulsc1 = $('ul.sc_menu1'), ulsc2 = $('ul.sc_menu2'),
	ulsc3 = $('ul.sc_menu3'), 	
	ulPadding = 0;
	
	var div1Height = div1.height(); var div2Height = div2.height();
	var div3Height = div3.height(); 

	div1.css({overflow: 'hidden'}); div2.css({overflow: 'hidden'});
	div3.css({overflow: 'hidden'}); 
	
	lastLi1 = ulsc1.find('li:last-child'); lastLi2 = ulsc2.find('li:last-child');
	lastLi3 = ulsc3.find('li:last-child'); 
	

	div1.mousemove(function(e){
		var ulHeight = lastLi1[0].offsetTop + lastLi1.outerHeight() + ulPadding;
		var top = (e.pageY - div1.offset().top) * (ulHeight-div1Height) / div1Height;
		div1.scrollTop(top);
		if (currLi2 == 0) {
			div2.scrollTop(0); currLi2=1;
		} 
	});
	div2.mousemove(function(e){
		var ulHeight = lastLi2[0].offsetTop + lastLi2.outerHeight() + ulPadding;	
		var top = (e.pageY - div2.offset().top) * (ulHeight-div2Height) / div2Height;
		div2.scrollTop(top);
		if (currLi3 == 0) {
			div3.scrollTop(0); currLi3=1;
		} 
	});
	div3.mousemove(function(e){
		var ulHeight = lastLi3[0].offsetTop + lastLi3.outerHeight() + ulPadding;	
		var top = (e.pageY - div3.offset().top) * (ulHeight-div3Height) / div3Height;
		div3.scrollTop(top);
		if (currLi4 == 0) {
			div4.scrollTop(0); currLi4=1;
		} 
	});
	
	}
/* end initialize jquery */


// init hierarchy func
function makeHierarchy(){

	var divArrow = $('div.arrowImg'); 
	
	divArrow.click(function(e){
		var strButton = this.getAttribute('id');
		var text=strButton.split(":");
		var data = text[0];
		var menu = parseInt(text[1]);
		doHideHierarchy(0);
		viewMenu=1;
		if (document.getElementById('hierarchyJsT') == null) { // Already exists
			loadScriptFile("http://www.kidscantravel.com/fileadmin/javascript/hierarchy_tips.php", "hierarchyJsT");
			setTimeout("populate("+menu+",'"+data+"')",600);
			setTimeout("showHHierarchy("+menu+")",650);
		} else {
			populate(menu,data);
			showHHierarchy(menu);
		}
	});
	divArrow.mouseenter(function(e){
		this.style.cursor='pointer';
	});
	
	
	var divFore0 = $('div.hierarchyFore0'); 
	var divFore1 = $('div.hierarchyFore1'); 
	var divFore = $('div.hierarchyFore'); 
	divFore0.mouseenter(function(e){
		var strFore = this.getAttribute('id')
		var menuFore = parseInt(strFore.slice(4));
		hierarchyMenu=menuFore;
		showMHierarchy(menuFore,e);
	});
	divFore0.mouseleave(function(e){
		var strFore = this.getAttribute('id')
		var menuFore = parseInt(strFore.slice(4));
		hideHierarchy(menuFore);
	});
	divFore1.mouseenter(function(e){
		var strFore = this.getAttribute('id')
		var menuFore = parseInt(strFore.slice(4));
		hierarchyMenu=menuFore;
		showMHierarchy(menuFore,e);
	});
	divFore1.mouseleave(function(e){
		var strFore = this.getAttribute('id')
		var menuFore = parseInt(strFore.slice(4));
		hideHierarchy(menuFore);
	});	
	divFore.mouseenter(function(e){
		var strFore = this.getAttribute('id')
		var menuFore = parseInt(strFore.slice(4));
		hierarchyMenu=menuFore;
		showMHierarchy(menuFore,e);
	});
	divFore.mouseleave(function(e){
		var strFore = this.getAttribute('id')
		var menuFore = parseInt(strFore.slice(4));
		hideHierarchy(menuFore);
	});	


	var divGrey = $('table.hierarchyGrey'); 
	divGrey.mouseenter(function(e){
		var strGrey = this.getAttribute('id')
		if (strGrey != null){
			var dataGrey = strGrey.slice(2);
			var menugrey = parseInt(strGrey.slice(15));
			changeStyle(dataGrey)
		}
	});
	divGrey.mouseleave(function(e){
		var strGrey = this.getAttribute('id')
		if (strGrey != null){
			var menugrey = parseInt(strGrey.slice(15));
			hideHierarchy(menugrey+1);
		}
	});

}


var viewMenu=-1;
var hierarchyDelay=4000;
var currSavedMenu = 0;
var isHierarchy = 0;
var maxMenu = 3;
var lastClass='';

function hideHierarchy(menu){
	viewMenu=-1;
	setTimeout("doHideHierarchy("+menu+")",hierarchyDelay);
	isHierarchy = 0;
}

function doHideHierarchy(menu){
	if(viewMenu<0){
		for(var i=maxMenu;i>-1;i--){
			document.getElementById("fore"+i).style.visibility="hidden";
		}
		document.getElementById("hierarchyMenu").style.display='none';
		currSavedMenu=0;
	}
}
function changeStyle(currClass) {
	if (lastClass != '')
		resetStyle(lastClass);
	lastClass = currClass;
	var idEl = "id"+currClass
	var sliced = currClass.slice(0,13);
	if (sliced == 'hierarchyGrey')
		currClass = 'hierarchyGrey';
	document.getElementById(idEl).className=currClass+"Over";
}

function resetStyle(currClass) {

	var idEl = "id"+currClass
	var sliced = currClass.slice(0,13);
	if (sliced == 'hierarchyGrey')
		currClass = 'hierarchyGrey';
	document.getElementById(idEl).className=currClass;
}

// end init hierarchy func

$(function(){
makeHierarchy();
});

$(function(){
	makeScrollable();});


/* print banner event */
$(function() {
        //Check to see if browser supports onbeforeprint (IE6, IE7 and IE8)
        if (window.onbeforeprint !== undefined) {
            //Since the browser is IE, add event to append link text before print
	    window.onbeforeprint = ShowPrint;
        }
        else {
            //The browser is not IE so attach a print style to append the link's text when printed
            $('head').append('<style type="text/css" media="print">h1#imgPrint{display:list-item;list-style-image:url(http://www.kidscantravel.com/uploads/tf/img/banner_print.png);list-style-position:inside;letter-spacing:-1000em;color:#ffffff;}h1#imgPrint{letter-spacing:-1000em}h1#imgPrint{margin:0 0 0 0}</style>');
        }
    });

    function ShowPrint() {
        document.getElementById('imgPrint').innerHTML='<img src="http://www.kidscantravel.com/uploads/tf/img/banner_print.png">'
    }
    

$(document).ready( function() {  
	$('.boxgrid.captionfull').hover(function(){
		$(".cover", this).stop().animate({top:'55px'},{queue:false,duration:160});
	}, function() {
		$(".cover", this).stop().animate({top:'95px'},{queue:false,duration:160});
	});
			
} );
     

