// Java Script Document

$(document).ready(function() {

    mainMenu();
    makeHomeRotator();
    thumb();
    toggleInputFields();
    toggleButton();
    showPopUp();
    carousels();
    selectioy();
    addPopUpToSecuredLinks();
});

function addPopUpToSecuredLinks() {
    $('a').each(function(index) {
        if ($(this).attr("secured") != null && $(this).attr("secured")) {
            $(this).removeAttr("secured");
            $(this).attr("href","javascript:popUp('" + $(this).attr("href") + "');");
        }
    });
}

function mainMenu(){
	$('.leftColumnBig .kalendarItem:eq(0)').css("margin-top","18px");
	$('.rightColumnIn .kalendarItem:eq(0)').css("margin-top","12px");
	$('.webUl:eq(0)').css("margin-right","60px");
}

function makeHomeRotator() {
	var rotObj = new Object();
	var itemsCount = $('div.rotatorContainer div.item').length;
	var currentRotItem;
	var isFading = false;
	var homeRotatorTime = 3;
	var homeRotatorTimer;
	
	 $('div.rotatorContainer').append('<div class="rotator-pager"></div>');
	for (var i = 0; i < itemsCount; i++) {
		$('div.rotator-pager').append('<div class="item"><!--  --></div>');
	}
	
	$('div.rotator-pager div.item').each(function(i) {
		$(this)
		.hover(
			function() {
				$(this).addClass('hover');
			},
			function() {
				$(this).removeClass('hover');
			}
		)
		.click(
			function() {
				if ($(this).hasClass('active')) return;
				if (isFading) return;
				isFading = true;
				$('div.rotator-pager div.item').removeClass('active');
				$(this).addClass('active');
				clearInterval(homeRotatorTimer);
				$('div.rotatorContainer > div.item:nth-child(' + currentRotItem + ')').fadeOut(400);
				currentRotItem = i + 1;
				$('div.rotatorContainer > div.item:nth-child(' + currentRotItem + ')').fadeIn(400, 
					function() {
						isFading = false;
						homeRotatorTimer = setInterval(rotate, homeRotatorTime * 1000);
					}
				);
			}
		)
	});
	
	currentRotItem = 1;
	$('div.rotator-pager div.item:nth-child(1)').addClass('active');
	$('div.rotatorContainer > div.item:nth-child(1)').show();
	
	homeRotatorTimer = setInterval(rotate, homeRotatorTime * 1000);
	
	function rotate() {
		$('div.rotatorContainer > div.item:nth-child(' + currentRotItem + ')').stop(true, true);
		clearInterval(homeRotatorTimer);
		$('div.rotator-pager div.item').removeClass('active');
		$('div.rotatorContainer > div.item:nth-child(' + currentRotItem + ')').fadeOut(600);
		currentRotItem++;
		if (currentRotItem > itemsCount) currentRotItem = 1;
		$('div.rotator-pager div.item:nth-child(' + currentRotItem + ')').addClass('active');
		$('div.rotatorContainer > div.item:nth-child(' + currentRotItem + ')').fadeIn(600, 
			function() {
				isFading = false;
				homeRotatorTimer = setInterval(rotate, homeRotatorTime * 1000);
			}
		);
	}
}

function thumb() {
	$('.thumb').append('<span class="tl"></span><span class="tr"></span><span class="bl"></span><span class="br"></span>');
}

function toggleInputFields() {
    $("input.decorInput").each(function() {
        $(this).wrap('<span class="inputHolder"></span>');
        $(this).before('<span class="inputStart"></span>');		
        $(this).after('<span class="closeBg"></span>');
//        $(this).css("width", $(this).width() - 10);
		 $(this).css("width", parseInt($(this).css("width")) -10);
    });
}

function toggleButton(){
    $("input.btnDecor").each(function() {
		$(this).wrap('<span class="btnDecorated"></span>');
        $(this).before('<span class="btnLeft"></span>');		
        $(this).after('<span class="btnRight"></span>');
		$(this).wrap('<span class="btnMid"></span>');
		$(this).removeClass('btnDecor')
    });
	
	$('.btnDecorated').mouseover(function() {
	$(this).addClass('hoverBtn');
	});
	$('.btnDecorated').mouseout(function() {
	$(this).removeClass('hoverBtn');
	});

}

//function watermark(){
	
//	 $(".login").Watermark("Gebruikersnaam","#999999");
// 	 $(".password").Watermark("Wachtwoord","#999999");
//}

function watermark(login){
    $(".login").Watermark("" + login + "", "#999999");
    $(".password").Watermark("Wachtwoord", "#999999");
}

function showPopUp() {
    $('.showPopUp').hover(
	function() {
	   $(this).find('.popUpContent').stop(true, true);
		$(this).addClass('hoverl');
		if ($.browser.msie == true) {
	        $(this).find('.popUpContent:first').show();
	    } else {
	        $(this).find('.popUpContent:first').show();
			$(this).addClass('hoverl');
	    }
	},
		function() {
		    if ($.browser.msie == true) {
		        $(this).find('.popUpContent:first').hide();
				$('.showPopUp').removeClass('hoverl');
		    } else {
		        $(this).find('.popUpContent:first').hide();
				$(this).removeClass('hoverl');
		    }
		}
	);
}

function popUp() {
    var heightPopup;
    setTimeout(function() {
        heightPopup = (document.body.clientHeight > $(document).height()) ? document.body.clientHeight : $(document).height();
        heightPopup = (parseInt($('.siteContainer').height()) > heightPopup) ? parseInt($('.overlay').height()) : $(document).height();
        $('.overlay').css('height', heightPopup + 'px');
    }, 100);
	$('.securedItemMark').click(function() {
	$('.overlay').css('visibility', 'visible')
	$('.overlay').animate({ opacity: 1 }, 300);
	$('.popupLogin').css('display', 'block') 
									  });
	$('.overlay').click(function() {
	$('.overlay').css('visibility', 'hidden')
	$('.overlay').animate({opacity: 0}, 300);
	$('.popupLogin').css('display', 'none') 
 
});
	$('.closePop').click(function() {
	$('.overlay').css('visibility', 'hidden')
	$('.overlay').animate({opacity: 0}, 300);
	$('.popupLogin').css('display', 'none') 
 
});
}

function popUpLog(classname) {
    var heightPopup;
    setTimeout(function() {
        heightPopup = (document.body.clientHeight > $(document).height()) ? document.body.clientHeight : $(document).height();
        heightPopup = (parseInt($('.siteContainer').height()) > heightPopup) ? parseInt($('.overlay').height()) : $(document).height();
        $('.overlay').css('height', heightPopup + 'px');
    }, 100);
	$('.overlay').css('visibility', 'visible')
	$('.overlay').animate({ opacity: 1 }, 300);
	$(classname).css('display', 'block') 


	$('.overlay').click(function() {
	$('.overlay').css('visibility', 'hidden')
	$('.overlay').animate({opacity: 0}, 300);
	$(classname).css('display', 'none') 
 
});
	$('.closePop').click(function() {
	$('.overlay').css('visibility', 'hidden')
	$('.overlay').animate({opacity: 0}, 300);
	$(classname).css('display', 'none') 
 
});
}

function popUp(link) {
    var heightPopup;
    setTimeout(function() {
        heightPopup = (document.body.clientHeight > $(document).height()) ? document.body.clientHeight : $(document).height();
        heightPopup = (parseInt($('.siteContainer').height()) > heightPopup) ? parseInt($('.overlay').height()) : $(document).height();
        $('.overlay').css('height', heightPopup + 'px');
    }, 100);
   
        $('.overlay').css('visibility', 'visible')
        $('.overlay').animate({ opacity: 1 }, 300);
        $('.popupLogin').css('display', 'block')
    
    $('.overlay').click(function() {
        $('.overlay').css('visibility', 'hidden')
        $('.overlay').animate({ opacity: 0 }, 300);
        $('.popupLogin').css('display', 'none')
    });
    $('.closePop').click(function() {
        $('.overlay').css('visibility', 'hidden')
        $('.overlay').animate({ opacity: 0 }, 300);
        $('.popupLogin').css('display', 'none')
    });

    obj = document.getElementById('hiddenredirect');
    if (obj != null)
        obj.value = link;
}


function saldorew(linkin){
$('.contKalPop').click(function(){
	window.location = "" + linkin + ""	
		   });
	
	}

function popUpInside(link) {
    var heightPopup;
    setTimeout(function() {
        heightPopup = (document.body.clientHeight > $(document).height()) ? document.body.clientHeight : $(document).height();
        heightPopup = (parseInt($('.siteContainer').height()) > heightPopup) ? parseInt($('.overlay').height()) : $(document).height();
        $('.overlay').css('height', heightPopup + 'px');
    }, 100);
    $('.overlay').css('visibility', 'visible')
    $('.overlay').animate({ opacity: 1 }, 300);
    $('.popupLogin').css('display', 'block')

    $('.overlay').click(function() {
        $('.overlay').css('visibility', 'hidden')
        $('.overlay').animate({ opacity: 0 }, 300);
        $('.popupLogin').css('display', 'none')

    });
    $('.closePop').click(function() {
        $('.overlay').css('visibility', 'hidden')
        $('.overlay').animate({ opacity: 0 }, 300);
        $('.popupLogin').css('display', 'none')
    });

    obj = document.getElementById('hiddenredirect');
    if (obj != null)
        obj.value = link;
}
function carousels(){

var index = $('div.kalendarContainer ul li').index($('li.activek'));
var indexh = 0;
if (indexh > index){
	indexh == 0;
	}
	else if (index > indexh){
		indexh = index-2;
		}
	if (indexh == 16)
	{
		indexh = 15;
		}
	else if (index == 1){
		indexh = 0;
		}

$('.kalendarContainer li span').before('<span class="kalenspa"></span>').after('<span class="kalenspa"></span>');
$('.kalendarContainer').jCarouselLite({
    btnNext: ".next",
    btnPrev: ".prev",
	start: indexh,
	visible: 4,
	circular: false
});


$('.itemCarContainer').jCarouselLite({
	btnNext: ".nexti",
    btnPrev: ".previ",
	speed: 2000,
	auto: 2000,
	stopControl:'.themeCont button'
});
}

function selectioy(){
var params = {
	        changedEl: ".lineFormT",
	        visRows: 10,
	        scrollArrows: true
}
	cuSel(params);
	
	var params = {
	        changedEl: ".lineForm",
	        visRows: 10,
	        scrollArrows: true
}
	cuSel(params);
}


