/* This script by $criptMaster B  Duall 2010 */
/* www.duall.be */


$(document).ready(function(){

	loginBox();
	homepage();
	tourpage();
	external();
	comments();
	musicplayer();
	//popup();
	

});
function musicplayer() {
	
	
	$('p.musicplayer a').click(function(){
		
		window.open('http://goosemusic.com/musicplayer/index.html','GOOSE MUSICPLAYER',
		'width=820,height=480,scrollbars=no,toolbar=no,location=no,resizable=no,menubar=no,status=no'); 
		return false;
		
	});
	
}
function comments() {
	
	$('#trackbackCntr').remove();
	$('#commentForm').hide();
	$('#commentsClicker').click(function(){
		$('#commentForm').slideToggle();
		
	});
	
}

function external() {


    $("a[rel=external]").click(function(){
        window.open($(this).attr("href")); 
        return false;
        });
}

function popup() {
	

//if ($.cookie('popup') != 'on') {	
	$('div.mask').show();
	$('div#popupWrapper img').hide();
	$('div#popupWrapper').fadeIn(function() {
		$('div#popupWrapper img').fadeIn("slow");
	});
	$('#popupWrapper a.action').click(function(){
		$("div#popupWrapper").hide();
		$('div.mask').fadeOut();
		//$.cookie("popup", "on",{domain: 'www.goosemusic.com'});
		return false;
        
	});
	
//	};
}

function loginBox(){
	
	$('#formBox').hide();
	$('#linkBox a').toggle(
		function(){
			
			$('#formBox').slideDown();
		},
	function(){
			$('#formBox').slideUp();
			
		}
		);
	
}

function tourpage() {
	
	vandaag = new Date();
	vandaag.setHours(0,0,0,0);
	vdoffset = vandaag.getTimezoneOffset()*60000;
	vandaag = vandaag.getTime();
	vandaag = vandaag + vdoffset;
	$('h3 span.datetext').each(function(){
		
		datum = $(this).text();
		$(this).text(datum.replace(/\//gi,'.'));
		datum = datum.split('/');
		for (var i=0; i < datum.length; i++) {
			parseInt(datum[i]);
		};
		datum[1] = datum[1]-1;
		tourdatum = new Date(datum[2],datum[1],datum[0],0,0,0,0);
		//console.log(tourdatum);
		tdoffset = tourdatum.getTimezoneOffset()*60000;
		tourdatum = tourdatum.getTime();
		tourdatum = tourdatum + tdoffset;
		//console.log($(this).text(),tourdatum,tdoffset);
		if (vandaag < tourdatum) {
			$(this).parents('div.tourdate').addClass('future');
		} else if (vandaag == tourdatum) {
			$(this).parents('div.tourdate').addClass('vandaag');
		} else {
			$(this).parents('div.tourdate').addClass('past');
		};
		$('.future').first().addClass('first');
	});
	
	
	$('ul#tourNav a').each(
		
		function(){
			var country = $(this).attr('href');
			country = country.substring(1); //remove #
			if($('div.'+country+'.future').length || $('div.'+country+'.vandaag').length) {
				return true;
			} else {
				$(this).parent('li').remove();
			}
			
		});

	$('ul#tourNav a').click(function(){
		
		var country = $(this).attr('href');
		country = country.substring(1); //remove #

		$('ul#tourNav a').removeClass('active');
		$(this).addClass('active');
		
		$('div.tourdate').hide();
		
		if ($('div.'+country+'').length) {
				if ($('li.showall').length) {
				} else {
					$('ul#tourNav').append('<li class="showall">');
					$('li.showall').append('<a>');
					$('li.showall a').text("show all").attr('href','#');
				}
			$('div.future.'+country+', div.vandaag.'+country+'').show();
			$('li.showall a').click(function(){
				$('div.future, div.vandaag').show();
				$(this).parent('li').remove();
				$('ul#tourNav a').removeClass('active');
				
			});
		
		} else {
			
			$('div.future, div.vandaag').show();
			
			
		};
	});
	

}

function homepage() {
	
	$('.boxImg p').each(
		function(){
			cat = $(this).parents('.homeBox').attr("id");
			var rm = Math.floor(Math.random()*17);	$(this).css("background-image","url(/goose/wp-content/themes/goose/HOME_BEELDEN/HOME_"+cat.toUpperCase()+"_0"+rm+".jpg)");
			//console.log(cat);
			
		});
}
