/* Development logs */
window.log = function(){
	log.history = log.history || [];
	log.history.push(arguments);
	if(this.console){
		console.log( Array.prototype.slice.call(arguments) );
	}
};

//Shuffle array
Arrshuffle = function(o){ 
	for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
	return o;
};

/**
 * Case refresh on home
 */
var CasesArray = new Array();

var CaseAnimationProgress = false;

function CaseRefresh()
{
	//4 New random cases in array
	RefresArray = new Array();
	RefresArray = Arrshuffle(CasesArray);
	
	if (CaseAnimationProgress) {
		return;
	}
	
	CaseAnimationProgress = true;
	
	$(".case-block").each(function(i, item){
		//Leave
		$(item).delay(i * 50).animate({
				opacity: 0.25,
				left: '+=50',
				height: 'toggle'
		  }, 250, function() {
				//Set new html
				$(item).html('<a href="'+KJ.casesurl+RefresArray[i]['URL']+'"><p class="title">'+RefresArray[i]['Naam']+'</p><div class="blockbg">&nbsp;</div><div class="blockimg"><a href="'+KJ.casesurl+RefresArray[i]['URL']+'"><img src="'+KJ.relimg+'/'+RefresArray[i]['Afbeelding']+'"/></a></div></a>');

				//Place back
				$(item).delay(i * 100).animate({
					opacity: 100,
					left: '-=50',
					height: 'toggle'
				});

			
		  });	
	});
	
	setTimeout(function(){
		CaseAnimationProgress = false;
	}, 1100);
}

$(function(){
	
	//Menu hover 
	$('#navigation li').hover(function(){
		$(this).children("a").css('color','#FFF');
	}, function(){
		$(this).children("a").css('color','#636363');
	});
	
	//Shadowbox
	Shadowbox.init();

	//Bevels
	$('.content-video').corner("round 5px");
	$('#support').corner("bevel 1px");
        $('.content-easyparty').corner("round 5px");
	
	//Open pavo video
	$('#video-pavo').bind({
		click: function()
		{
			Shadowbox.open({
							content:    '<iframe src="http://player.vimeo.com/video/16125551?autoplay=1" width="850" height="450"></iframe>',
							player:     "html",
							title:      "Pavo Awards",
							width:      850,
							height:		450
			});
		}
	});
	
	//Style picker
	$('.pick-style').bind({
		click: function()
		{
			var style = $(this).data('id');
			$('body').expose();
			$.getJSON(KJ.baseurl + 'ajax/change_style?style='+style, function(json){
				window.location=KJ.baseurl
			});			
		}
	});
	
	//Cases switcher
	$('#arrow-cases').bind({
		click: function() {
			CaseRefresh();		
		}
	});

});
