// JavaScript Document

$(document).ready(function(){
	//sliderBox();
	//jQuery('.sliderBox ').ismRotator({'isButtons' : 1,  'isRotating': 1}); 
	watermarkList();
	tabsInit();
	btn();
	imageKarousel();
	siteMap();
});


function siteMap(){
	$('.sitemapList > li:nth-child(2n)').addClass('lastInLine');
	$('.sitemapList > li.lastInLine').each( function(){
		if($(this).height() < $(this).prev().height()){
			$(this).css("height", $(this).prev().height());
			}
		else{
			$(this).prev().css("height", $(this).height());
			}
	});
}

function imageKarousel (){
	var imageSource= "url(" + $('.imageCarousel ul li:first img').attr("bigPic") + ")";
	$('.imageCarousel .bigImage').css( "background" , imageSource);
	
	$('.imageCarousel ul li img').click( function(){
		imageSource= "url(" + $(this).attr("bigPic") + ")";
		$('.imageCarousel .bigImage').css( "background" , imageSource);
	});
}

function btn(){
	if(!$('.btn').hasClass('decorated')){
		$('.btn').append('<ins></ins>').addClass('decorated');
	}
}


function tabsInit(){
	var activeTab;
	$('.tabsContainer').prepend('<div class="tabLine"></div>');
	$('.tabsContainer ul li .tabTitle').each( function(){
		$('.tabsContainer .tabLine').append($(this).detach());
	});
	$('.tabLine .tabTitle:nth-child(' + ($('.tabsContainer ul li.active').index() + 1) + ')').addClass('active');

	$('.tabsContainer .tabLine .tabTitle').click(function () {
	    $('.tabsContainer .tabLine .tabTitle').removeClass('active');
	    $('.tabsContainer ul li.active').removeClass('active');
	    activeTab = parseInt($(this).index() + 1);
	    $('.tabsContainer ul li:nth-child(' + activeTab + ')').addClass('active');
	    $(this).addClass('active');
	    if ($(this).index() == 1) {
	        $("#player").empty();
	        flowplayer('player', { src: '/scripts/flowplayer/flowplayer-3.2.7.swf', wmode: 'opaque' });
	    } else {
	        $("#player").empty();
	    };
	});
}	

function watermarkList(){

	$("#mapInput").Watermark("Hapert dealers bij mij in de buurt > ","#008bc4");
}


/*
var BoxItemTimer; //miliseconds
var currentBoxItem =1;
var selectedItem = -1;

function sliderBox(){
	$('.sliderBox').each( function() {
		$(this).prepend('<div class="sliderBoxButtons"></div>');
		$(this).find('li').each( function(){
			$(this).parent().parent().find('.sliderBoxButtons').append('<a><img src="img/welkom_spot.gif" style="top: 0px;"></a>');
		});
		$(this).find(".sliderBoxButtons a:first").addClass('active').find("img").css("top", "-10px");
		$(this).find("ul li:first").addClass('active');
	});
	//changeSlideInBox();
	$('.sliderBoxButtons a').click( function(){
		selectedItem = $(this).index()+1;
		$(this).parents('.sliderBox').find('.sliderBoxButtons a.active').removeClass('active');
		$(this).addClass('active');
		console.log("onClick index =" + selectedItem);
		clearTimeout(BoxItemTimer);
		BoxItemTimer = setTimeout(changeSlideInBox, 1000);
	});

}

function changeSlideInBox() {
	
	clearTimeout(BoxItemTimer);
	$('.sliderBox').each( function(){
		if($(this).find('.sliderBoxButtons a.active').index()!=$(this).find('ul li').index())
		$('.sliderBox ul li:nth-child(' + currentBoxItem + ')').fadeOut(300, function() {
		console.log("onTime index =" + currentBoxItem);
			$(".sliderBoxButtons a:nth-child(" + currentBoxItem + ")").find("img").animate({top:"0px"}, 300);
			if(selectedItem > 0){
				currentBoxItem = selectedItem;
				selectedItem = -1;
				}
			else{
				currentBoxItem++;				
				}

			if (currentBoxItem > 3) currentBoxItem = 1;
			$(".sliderBoxButtons a:nth-child(" + currentBoxItem + ")").find("img").animate({top:"-10px"}, 300);
			$(".sliderBox ul li:nth-child(" + currentBoxItem + ")").fadeIn(300);
			//BoxItemTimer = setTimeout(changeSlideInBox, 1000);
	
		});
	});
}*/
