﻿


$(document).ready(function() {
	jQuery(".flap-closed").mouseover(function() {
		jQuery(this).attr('style', 'background-image: url(' + jQuery(this).attr('rel') + ');');
	});
	jQuery(".flap-closed").mouseout(function() {
		jQuery(this).attr('style', '');
	});
	$(".bonus-wrapper").fadeIn(3000);
	/* LOUNGE */
	var loungebottom=150;
	$("#lounge-menu").css("bottom", "-"+ loungebottom +"px");
	
	jQuery("#signupChristmasCalendar").live("click", function() {
		var mail = jQuery("#CalendarMail").val();
		$.ez( 'Casino::signupNewsletter::'+mail, {arg1: 'hi!'}, function( data )
		{
			if ( data.content.status == 1 )
			{
				jQuery(".christmas-calendar-form").fadeOut();
				alert("Du er nå påmeldt til julekalenderen.");
			}
			else
			{
				alert("Vennligst fyll inn en gyldig e-postadresse og prøv igjen");
			}
		});
		return false;
	});
	
	/* SITEMA LIST */
	/*
	$(".sitemap-list .has-child").click(function() {
		if ( $(this).attr('class') == 'closed has-child' || $(this).attr('class') == 'has-child closed' )
		{
			$(this).addClass('open');
			$(this).removeClass('closed');
			var sitemap_id=$(this).attr('rel');
			$.ez( 'Casino::fetchSiteMap::'+sitemap_id, {arg1: 'hi!'}, function( data )
			{
				$('#' + data.content.id).html(data.content.tpl);
			});
			
		}
		else if ( $(this).attr('class') == 'open has-child' || $(this).attr('class') == 'has-child open' )
		{
			$(this).addClass('closed');
			$(this).removeClass('open');
		}
	});
	*/
	$('#open-lounge').click(function() {
		var bottom=$("#lounge-menu .first-level").height()-43;
		$("#lounge-menu").animate({"bottom":""+ bottom +"px"}, "slow");
		$("#open-lounge").hide();
		
		/*
		}, function() {
			$("#lounge-menu").animate({"bottom":"-"+ loungebottom +"px"}, "slow");
			$(".lounge-logo").show();
		*/
	});
	$('#lounge-menu .close-trans, .lounge-header').click(function() {
		$("#lounge-menu").animate({"bottom":"-"+ loungebottom +"px"}, "slow", function() {
			$("#open-lounge").fadeIn();
		});
	});
	$("#language-selector").mouseover(function() {
		$("#language-list").show();
	});
	$("#language-selector").mouseout(function() {
		$("#language-list").hide();
	});
	
	$('#main-menu li').mouseover(function(){
		var root_id=$(this).attr('id');
		var root=root_id.split('-');
		$('#sub-' + root[1]).show();
	});
	$('#main-menu li').mouseout(function(){ 
		var root_id=$(this).attr('id');
		var root=root_id.split('-');
		$('#sub-' + root[1]).hide();
	});
	
	
	/* hide or show start bonuslist */
	$('.toggle-expand-collapse, .choose-bonus').toggle(function() {
		$('.bonus-wrapper .bonus-list-game').slideUp();
		$('.toggle-expand-collapse').addClass('bonus-toggle-collapsed');
		$('.bonus-wrapper').addClass('bottom-padding');
	},function() {
		$('.bonus-wrapper .bonus-list-game').slideDown();
		$('.toggle-expand-collapse').removeClass('bonus-toggle-collapsed');
		$('.bonus-wrapper').removeClass('bottom-padding');
	});
	
	
	$('.first-level li').mouseover(function()  {
		var id=$(this).attr('id');
		var id_built = id.split('-');
		var submenu =  $('#sub-' + id_built[1]);
		var first_height=submenu.height();
		var lounge_height=$("#lounge-menu .first-level").height();
		var trigger_menu = $(this);
		var new_submenu_pos=lounge_height-trigger_menu.position().top-15;
		submenu.css('bottom', new_submenu_pos);
		/*
		if ( first_height > lounge_height )
		{
			submenu.css('bottom', '20px');
		}*/
		submenu.show();
		
	});
	$('.first-level li').mouseout(function()  {
		var id=$(this).attr('id');
		var id_built = id.split('-');
		$('#sub-' + id_built[1]).hide();
	});
	
	
	/* BONUS SHOW/HIDE */
	$('.close-white').live('click', function() 
	{
		closeAllBonusWindows();
	});
	$('.bonus-wrapper .bonusline').live('click', function() {
		closeAllBonusWindows();
		$(this).parent().addClass('active');
		var bonuslineid=$(this).attr('id');
		var bonusline=bonuslineid.split('-');
		$('#' + bonuslineid + ' .arrow-right').css('display', 'block');
		var bonusinfo=$('#bonus-' + bonusline[1]);
		bonusinfo.show();
		if ( $(this).parent().index() > 0 )
		{
			var marginextra = 50*$(this).parent().index();
			var marginnew =	36+marginextra;
			bonusinfo.attr('style', 'margin-top: ' + marginnew + 'px !important; display: block;');
		}
	});
	$('.casino-guide-wrapper .bonusline').live('click', function() {
		closeAllBonusWindows();
		$(this).parent().addClass('active');
		var bonuslineid=$(this).attr('id');
		var bonusline=bonuslineid.split('-');
		$('#' + bonuslineid + ' .arrow-right').css('display', 'block');
		var bonusinfo=$('#bonus-' + bonusline[1]);
		bonusinfo.show();
		if ( $(this).parent().index() > 0 )
		{
			var marginextra = 50*$(this).parent().index();
			var marginnew =	196+marginextra;
			bonusinfo.attr('style', 'margin-top: ' + marginnew + 'px !important; display: block;');
		}
	});
	
	/* SHOW/HIDE all bonuses */
	$(".bonus-wrapper .show-all-bonues").live('click', function(){
		$(".bonus-wrapper ul li").each(function()
		{
			if ( $(this).hasClass('show') )
			{
				$(this).addClass('hide');
				$(this).removeClass('show');
			}
			else if ( $(this).hasClass('hide') )
			{
				$(this).addClass('show');
				$(this).removeClass('hide');
			}
			else {}
		});
	});
	$(".casino-guide-wrapper .show-all-bonues").live('click', function(){
		$(".casino-guide-wrapper ul li").each(function()
		{
			if ( $(this).hasClass('show') )
			{
				$(this).addClass('hide');
				$(this).removeClass('show');
			}
			else if ( $(this).hasClass('hide') )
			{
				$(this).addClass('show');
				$(this).removeClass('hide');
			}
			else {}
		});
	});
	
	
	
	
	/* FOOTER MOUSE OVER */
	$('#footer ul li').mouseover(function() {
		var footerdemoboxid=$(this).attr('id');
		$('#footer ul li').each(function() {
			$('#' + $(this).attr('id') +'-box').hide();
		});
		
		
		$('#' + footerdemoboxid +'-box').show();
	});
	$('#footer ul li div').mouseout(function() {
		var footerdemoboxid=$(this).parent().attr('id');
		$('#' + footerdemoboxid +'-box').hide();
	});
	
	$('#change-bonus-country').live("change", function() {
		var value = $(this).val();
		$.ez( 'Casino::fetchBonusListForGameHTML::'+value, {arg1: 'hi!'}, function( data )
		{
			$('.bonus-wrapper ul').html(data.content);
		});
	});
	$('#change-country-casino-guide').live("change", function() {
		var value = $(this).val();
		$.ez( 'Casino::fetchCasinoListWithBonusForCountryHTML::'+value, {arg1: 'hi!'}, function( data )
		{
			$('#casinolist-right').html(data.content);
		});
	});
	$('.thumb').click(function() {
		var click_id=$(this).attr('id');
		click_id = click_id.split('-');
		Slidebox(click_id[1]);
	});
	
	/* Empty search input  */
	$('.searchText').click(function() {
		$(this).val('');
	});
	
	function closeAllBonusWindows()
	{
		$('.bonuswindow').each(function() {
			$(this).hide();
			$(this).parent('li').removeClass('active');
		});
		 $('.bonusline .arrow-right').each(function() {
			$(this).hide();
		 });
	}
	
	/* Empty commentfield */
	$('.has-overlay').focus(function() {
		var label_id=$(this).attr('id');
		$("#" + label_id + '-label').fadeOut();
	});
	$('.has-overlay').blur(function() {
		var label_id=$(this).attr('id');
		if ( $(this).val() == '' )
		{
			$("#" + label_id + '-label').fadeIn();
		}
	});
	
	/* FAQ 
	
	$('.faq-list li').click(function() {
		var faq_id 	= $(this).attr('id');
		faq_id		= faq_id.split('-');
		faq_id		= faq_id[1];
		
		if ( $(this).attr('class') == 'heading' )
		{
			$(this).addClass('heading-open');
			$(this).removeClass('heading');
			$('#answer-' + faq_id).css('display', 'block');
		}
		else if ( $(this).attr('class') == 'heading-open' )
		{
			$(this).addClass('heading');
			$(this).removeClass('heading-open');
			$('#answer-' + faq_id).css('display', 'none');
		}
	});
	*/
	$("#choose-category").change(function() {
		location='/casino/redirect/' + $(this).val() + '/0/218/(from)/faq';
	});
	setTimeout(function() {
		$("#right").animate({right: 0},'slow');
	}, 3500);
});








function Slidebox(slideTo,autoPlay){
    var animSpeed=1000; //animation speed
    var easeType='easeInOutExpo'; //easing type
	var sliderWidth=$('#slidebox').width();
	var leftPosition=$('#slidebox .container').css("left").replace("px", "");
	if( !$("#slidebox .container").is(":animated")){
		if(slideTo=='next'){ //next
			if(autoPlay=='stop'){
				clearInterval(autoPlayTimer);
			}
			if(leftPosition==-slideboxTotalContent){
				$('#slidebox .container').animate({left: 0}, animSpeed, easeType); //reset
				$('#slidebox .thumbs a:first-child').removeClass('thumb').addClass('selected_thumb');
				$('#slidebox .thumbs a:last-child').removeClass('selected_thumb').addClass('thumb');
			} else {
				$('#slidebox .container').animate({left: '-='+sliderWidth}, animSpeed, easeType); //next
				$('#slidebox .thumbs .selected_thumb').next().removeClass('thumb').addClass('selected_thumb');
				$('#slidebox .thumbs .selected_thumb').prev().removeClass('selected_thumb').addClass('thumb');
			}
		} else if(slideTo=='previous'){ //previous
			if(autoPlay=='stop'){
				clearInterval(autoPlayTimer);
			}
			if(leftPosition=='0'){
				$('#slidebox .container').animate({left: '-'+slideboxTotalContent}, animSpeed, easeType); //reset
				$('#slidebox .thumbs a:last-child').removeClass('thumb').addClass('selected_thumb');
				$('#slidebox .thumbs a:first-child').removeClass('selected_thumb').addClass('thumb');
			} else {
				$('#slidebox .container').animate({left: '+='+sliderWidth}, animSpeed, easeType); //previous
				$('#slidebox .thumbs .selected_thumb').prev().removeClass('thumb').addClass('selected_thumb');
				$('#slidebox .thumbs .selected_thumb').next().removeClass('selected_thumb').addClass('thumb');
			}
		} else {
			var slide2=(slideTo-1)*sliderWidth;
			if(leftPosition!=-slide2){
				clearInterval(autoPlayTimer);
				$('#slidebox .container').animate({left: -slide2}, animSpeed, easeType); //go to number
				$('#slidebox .thumbs .selected_thumb').removeClass('selected_thumb').addClass('thumb');
				var selThumb=$('#slidebox .thumbs a').eq((slideTo-1));
				selThumb.removeClass('thumb').addClass('selected_thumb');
			}
		}
	}
}
function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (
			anchor.getAttribute("href") && ( 
			anchor.getAttribute("rel") == "external" || 
			anchor.getAttribute("rel") == "external nofollow" || 
			anchor.getAttribute("rel") == "nofollow" || 
			anchor.getAttribute("rel") == "nofollow external" )
			)
		anchor.target = "_blank";
	}
}
window.onload = function() {
	externalLinks();
	
}



