$(document).ready(function(){
	if(fromClaim==true && toggleText!=undefined){
		toggleText();
	}
	$('#logoBox').click(function(){
		window.location.href='/';
	});
	
	$('.navigation_bottom_sw li.level2').mouseenter(function(){
		setHoveredClass(this);
	}).mouseleave(function(){
		unsetHoveredClass(this);
	});
	$('.navigation_bottom_sw > li.level1 > ul').prepend('<li style="height: 5px;" class="level2">&nbsp;</li>');
	$('.navigation_bottom_sw > li.level1 > ul').append('<li style="height: 5px;" class="level2">&nbsp;</li>');
	$('.navigation_bottom_sw').mouseenter(function(){
		openSlideUp(this);
	}).mouseleave(function(){
		closeSlideUp(this);
	});
	
	$('.navigation_bottom_hw li.level2').mouseenter(function(){
		setHoveredClass(this);
	}).mouseleave(function(){
		unsetHoveredClass(this);
	});
	$('.navigation_bottom_hw > li.level1 > ul').prepend('<li style="height: 5px;" class="level2">&nbsp;</li>');
	$('.navigation_bottom_hw > li.level1 > ul').append('<li style="height: 5px;" class="level2">&nbsp;</li>');
	$('.navigation_bottom_hw').mouseenter(function(){
		openSlideUp(this);
	}).mouseleave(function(){
		closeSlideUp(this);
	});
	
	$('.navigation_bottom_ref li.level2').mouseenter(function(){
		setHoveredClass(this);
	}).mouseleave(function(){
		unsetHoveredClass(this);
	});
	$('.navigation_bottom_ref > li.level1 > ul').prepend('<li style="height: 5px;" class="level2">&nbsp;</li>');
	$('.navigation_bottom_ref > li.level1 > ul').append('<li style="height: 5px;" class="level2">&nbsp;</li>');
	$('.navigation_bottom_ref').mouseenter(function(){
		openSlideUp(this);
	}).mouseleave(function(){
		closeSlideUp(this);
	});
	
	$('.navigation_bottom_faq li.level2').mouseenter(function(){
		setHoveredClass(this);
	}).mouseleave(function(){
		unsetHoveredClass(this);
	});
	$('.navigation_bottom_faq > li.level1 > ul').prepend('<li style="height: 5px;" class="level2">&nbsp;</li>');
	$('.navigation_bottom_faq > li.level1 > ul').append('<li style="height: 5px;" class="level2">&nbsp;</li>');
	$('.navigation_bottom_faq').mouseenter(function(){
		openSlideUp(this);
	}).mouseleave(function(){
		closeSlideUp(this);
	});
	
	$('.navigation_bottom_faq li.level3').mouseenter(function(){
		setHoveredClass(this);
	}).mouseleave(function(){
		unsetHoveredClass(this);
	});
	
	$('.navigation_bottom_faq li.level2').click(function(){
		openSlideUpSubmenu(this);
	});
	
	
	/*
	$('.navigation_bottom_hw > li.level1 > ul').prepend('<li style="height: 5px;" class="level2">&nbsp;</li>');
	
	$('.navigation_bottom_ref > li.level1 > ul').prepend('<li style="height: 5px;" class="level2">&nbsp;</li>');
	$('.navigation_bottom_right > li.level1 > ul').prepend('<li style="height: 5px;" class="level2">&nbsp;</li>');
	$('.navigation_bottom_faq > li.level1 > ul').prepend('<li style="height: 5px;" class="level2">&nbsp;</li>');
	
	
	
	$('.navigation_bottom_faq li.level2').click(function(){
		openSlideUpSubmenu(this);
	});
	
	
	$('.navigation_bottom_right li.level2').mouseenter(function(){
		setHoveredClass(this);
	}).mouseleave(function(){
		unsetHoveredClass(this);
	});
	$('.navigation_bottom_right').mouseenter(function(){
		openSlideUp(this);
	}).mouseleave(function(){
		closeSlideUp(this);
	});
	$('.navigation_bottom_right > li.level1').click(function(){
		openSlideUp($('.navigation_bottom_right'));
	});
	
	$('.navigation_bottom_faq li.level2').mouseenter(function(){
		setHoveredClass(this);
	}).mouseleave(function(){
		unsetHoveredClass(this);
	});
	$('.navigation_bottom_faq').mouseenter(function(){
		openSlideUp(this);
	}).mouseleave(function(){
		closeSlideUp(this);
	});
	$('.navigation_bottom_faq > li.level1').click(function(){
		openSlideUp($('.navigation_bottom_faq'));
	});
	
	
	
	
	$('.navigation_bottom_hw li.level2').mouseenter(function(){
		setHoveredClass(this);
	}).mouseleave(function(){
		unsetHoveredClass(this);
	});
	
	$('.navigation_bottom_ref li.level2').mouseenter(function(){
		setHoveredClass(this);
	}).mouseleave(function(){
		unsetHoveredClass(this);
	});
	
	$('.navigation_bottom_sw li.level2').mouseenter(function(){
		setHoveredClass(this);
	}).mouseleave(function(){
		unsetHoveredClass(this);
	});
	
	$('.navigation_bottom_faq li.level3').mouseenter(function(){
		setHoveredClass(this);
	}).mouseleave(function(){
		unsetHoveredClass(this);
	});
	
	
	$('.navigation_bottom_ref').mouseenter(function(){
		openSlideUp(this);
	}).mouseleave(function(){
		closeSlideUp(this);
	});
	
	$('.navigation_bottom_hw').mouseenter(function(){
		openSlideUp(this);
	}).mouseleave(function(){
		closeSlideUp(this);
	});
	
	$('.navigation_bottom_sw').mouseenter(function(){
		openSlideUp(this);
	}).mouseleave(function(){
		closeSlideUp(this);
	});
	
	
	$('.navigation_bottom_ref > li.level1').click(function(){
		openSlideUp($('.navigation_bottom_ref'));
	});
	$('.navigation_bottom_hw > li.level1').click(function(){
		openSlideUp($('.navigation_bottom_hw'));
	});
	$('.navigation_bottom_sw > li.level1').click(function(){
		openSlideUp($('.navigation_bottom_sw'));
	});
	
	*/
	
});


function setHoveredClass(e){
	if(!e.className){
		e=e[0];
	}
	$(e).addClass('hovered');
}

function unsetHoveredClass(e){
	if(!e.className){
		e=e[0];
	}
	$(e).removeClass('hovered');
}

function openSlideUpSubmenu(e){
	
	if(!e.className){
		e=e[0];
	}
	
	
	var wrapperULId='actMonsterUL';
	
	var iId='actOpenSlideDownSubmenu';//+Math.random();
	e.id=iId;
	
	//count li in subNavigation to calculate new height
	var liCount=$('#'+iId+' > ul > li');
	liCount=liCount.length;
	var tHeight=(liCount*16);
	
	
	//$('.navigation_bottom_faq ul.level2').animate({height: '0px'},500);
	//$('#'+iId+' ul.level2').animate({height:tHeight+'px'},500);
	
	//$('.navigation_bottom_faq li.level2 ul').animate({height: '0px'});
	//$('#'+iId+' li.level').animate({height: tHeight+'px'},500);
	//$('#'+iId).animate({height: (tHeight+17)+'px'},500);
	
	$('.navigation_bottom_faq ul.level2').slideUp('fast');
	$('#'+iId+' ul.level2').slideDown('fast');
	var monster=$('.navigation_bottom_faq ul.level1');
	try{
		$(monster).stop();
		$(monster).animate({height:(oriHeight+tHeight)+'px', top: (oriTop-tHeight)+'px'},500);
	}catch(e){
		
	}
	e.id='';
	
}

var oriHeight=0;
var oriMarginTop=0;
var oriTop=0;
var faqOpened=false;


function openSlideUp(e){
	
	if(faqOpened==false){
		/*
		if(!e.className){
			e=e[0];
		}
		
		var l=$("ul:first",e);
		$(l).stop();
		$(l).slideDown('slow');
		*/
		
		
		if(!e.className){
			e=e[0];
		}
		
		var xl=$("img:first",e);
		
		
		//mark Target-UL
		var iId='actOpenSlideUp';//+Math.random();
		e.id=iId;
		
		
		//get subNavigation
		var l=$("ul:first",e);
		
		//count li in subNavigation to calculate new height
		var liCount=$('li.level2',l[0]);
		//var test=liCount[0].height();
		
		liCount=liCount.length;
		//console.log(liCount);
		var hOffset=0;//$(xl).height()+3;//34;
		var tHeight=((liCount-2)*16)+10;
		var tMargin=tHeight+hOffset;
		var tTop=-1*($(xl).height()+tHeight);
		oriTop=tTop;
		//mark contained UL
		var cId='actContainingSlidingUp';
		var x=$('ul:first',e);
		x[0].id=cId;
		
		oriHeight=tHeight;
		oriMarginTop=-1*tMargin;
		
		var animationTime=500;
		var pHeight=($('#'+cId).height()/tHeight)*100;
		var aTime=animationTime-((pHeight*animationTime)/100);
		
		if($('#'+cId).height()<1){
			$('#'+cId).css('top','-'+$(xl).height()+'px');
		}
		$('#'+cId).stop();
		$('#'+cId).animate({height: tHeight+'px',top: tTop+'px'},aTime,null,function(){openSlideUp_callback();});
		//$('#'+cId).animate({marginTop: '-'+tMargin+'px', height: tHeight+'px'},aTime,null,function(){openSlideUp_callback();});
		
		
		// remove marks
		e.id='';
		x[0].id='';
		
		try{
			if($(e).hasClass('navigation_bottom_faq')){
				faqOpened=true;
			}
		}catch(ex){
			
		}
		
	}
}

function openSlideUp_callback(){
	
}

function closeSlideUp(e){
	
	
	
	
	if(!e.className){
		e=e[0];
	}
	
	try{
		if($(e).hasClass('navigation_bottom_faq')){
			faqOpened=false;
		}
	}catch(ex){
		
	}
	
	$('.navigation_bottom_faq ul.level2').hide('fast');
	
	var xl=$("img:first",e);
	//$(xl).height();
	
	
	//mark Target-UL
	var iId='actOpenSlideUp';//+Math.random();
	e.id=iId;
	
	//mark contained UL
	var cId='actContainingSlidingUp';
	var x=$('ul:first',e);
	x[0].id=cId;
	
	//count li in subNavigation to calculate new height
	var liCount=$('li',x[0]);
	liCount=liCount.length;
	var hOffset=0;//$(xl).height()+3;//34;//var hOffset=34;
	var tHeight=((liCount-2)*16)+10;
	var tTop=-1*$(xl).height();
	var animationTime=500;
	var pHeight=($('#'+cId).height()/tHeight)*100;
	var aTime=((pHeight*animationTime)/100);
	
	$('#'+cId).stop();
	$('#'+cId).animate({height: '0px',top: tTop+'px'},aTime,null,function(){closeSlideUp_callback();});
	//$('#'+cId).animate({marginTop: '-'+hOffset+'px', height: '0px'},aTime,null,function(){closeSlideUp_callback();});
	
	
	// remove marks
	e.id='';
	x[0].id='';
	
	
}

function closeSlideUp_callback(){
	
}



