var screen_width;
var screen_height;

function setFooterDecoration()
{
	screen_height = $(window).height();	
	screen_width = $(window).width();
	
	$('div.footer-swirl-right').css({'marginLeft': (screen_width-640)+'px'});
}

function mycarousel_fadeOut(carousel) {
	setStreamNavHidden();
	var JCcontainerID = carousel.clip.context.id;
	$('#' + JCcontainerID).fadeOut();
}

function mycarousel_fadeIn(carousel) {
	setStreamNav();
    var JCcontainerID = carousel.clip.context.id;
    $('#' + JCcontainerID).fadeIn();
}

function setStreamNav()
{
	$('div.streamer-nav').fadeIn('fast');		
}

function setStreamNavHidden()
{
	$('div.streamer-nav').fadeOut('fast');		
}

function setStreamerNavActive(carousel, item, idx, state)
{
	$('div.streamer-nav > ul > li > a').removeClass('active')
    $('div.streamer-nav > ul > li > a').eq(idx-1).addClass('active');
}

function streamer_initCallback(carousel)
{
    $('div.streamer-nav > ul > li > a').bind('click', function() {
        carousel.scroll(jQuery.jcarousel.intval($(this).attr('id').replace('streamer_item_','')));
        active_index = ($(this).attr('id').replace('streamer_item_',''))-1;
        $('div.streamer-nav > ul > li > a').removeClass('active')
      	$('div.streamer-nav > ul > li > a').eq(active_index).addClass('active');
        return false;
    });    
    
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

function blockActionClose()
{
	$('#content-action-container > li a').each(function(){
		$(this).removeClass('active');
	});
	$('#content-action-container > li ul').each(function(){
		$(this).hide();
	});	
}

function getOppadCode()
{
	$.ajax({
		type: 'POST',
		url: '/engine/flevo_on_ice__website__oppad__check_c&method=setCheckUrl',
		data:{
			code_s: $('input[name="code"]').val()
		},
		success: function(data){				
			if(data)
			{
				data = $('div.content-left h1').prop('outerHTML') + data;
				$('div.content-left').html(data);
			}
			else{
				alert('De code: '+$('input[name="code"]').val()+' was onjuist');
			}
		}
	});	
}

$(function(){
	setFooterDecoration();

	$('iframe').each(function(){
		var url = $(this).attr("src");
		$(this).attr("src",url+"?wmode=transparent");
	});
	
	/* Slider */
    $('#streamer').jcarousel({
    	wrap: 'wrap',
		auto: 8,
    	scroll: 1,
    	animation: 100,
        buttonNextHTML: null,
        buttonPrevHTML: null,  	
    	initCallback: streamer_initCallback,  
    	itemVisibleInCallback: setStreamerNavActive,  	
    	itemLastOutCallback: {
    		onBeforeAnimation: mycarousel_fadeOut,
    		onAfterAnimation: mycarousel_fadeIn
    	}
    });

	    $('#image-streamer').jcarousel({
    	wrap: 'both',
		auto: 8,
    	scroll: 1,
    	animation: 100,
        buttonNextHTML: null,
        buttonPrevHTML: null,  
		initCallback: streamer_initCallback,  
    	itemVisibleInCallback: setStreamerNavActive,  	
    	itemLastOutCallback: {
    		onBeforeAnimation: mycarousel_fadeOut,
    		onAfterAnimation: mycarousel_fadeIn
    	}
    }); 
	
	$('#content-action-container > li > a').click(function(){
		blockActionClose();
		$(this).addClass('active');
		$(this).siblings('ul').show();
		return false;
	});
	
	$('a.fancybox').fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	300, 
		'speedOut'		:	100, 
		'overlayShow'	:	false,
		'showCloseButton' : true,
		'overlayColor' : '#c1c1c1',
		'overlayShow' 	: true,
		'overlayOpacity': 0.9	
	});
	
	$('a.subscribe_trigger').click(function(){
		$('#subscribe_packages').slideDown('fast');
		return false;
	});
});

