$(document).ready(function () {
	
	// show/hide content
	$("#switch").click(function() {
		if($("#content_big").is(':hidden')){
			$("#content_big, #social").show();
			$(this).css('backgroundImage','url(../img/special/minus.gif)');
			}
		else{
			$("#content_big, #social").hide();
			$(this).css('backgroundImage','url(../img/special/plus.gif)');
			}
		});
	
	// show/hide scroll-buttons
	/*
	$("#move").hover(
		function () {
    		$(".scroll.big.up").css('background','url(../img/special/scroll_up_big.png) no-repeat');
    		$(".scroll.big.down").css('background','url(../img/special/scroll_down_big.png) no-repeat');
    		}, 
    	function () {
    		$(".scroll.big.up").css('backgroundImage','');
    		$(".scroll.big.down").css('backgroundImage','');
			})
	*/
	$("#move .scroll_box").hover(
		function () {
			var scroller, height, box, height_box;
			if($(this).parent().attr("class") == 'box s2 fix')
				scroller = 'medium';
			//else if($(this).parent().attr("class") == 'cont_box box s3')
			else if($(this).parent().attr("id") == 'cal')
				scroller = 'big';
			else
				scroller = 'small';
				
			height = document.getElementById($(this).find(".cont_box").attr("id")).offsetHeight;
			box = $(this).parent().find(".cont_box").attr("id");
			height_box;
			box == 'pict' ? height_box = 650 : height_box = 610;
			if(height > height_box){
	    		$(this).find('.scroll.'+scroller+'.up').css('background','url(../img/special/scroll_up_'+scroller+'.png) no-repeat');
    			$(this).find('.scroll.'+scroller+'.down').css('background','url(../img/special/scroll_down_'+scroller+'.png) no-repeat');
    			}
    		else{
    			$(this).find('.scroll.'+scroller+'.up').hide();
    			$(this).find('.scroll.'+scroller+'.down').hide();
    			}
    		}, 
    	function () {
    		var scroller;
    		if($(this).parent().attr("class") == 'box s2 fix')
				scroller = 'medium';
			else if($(this).parent().attr("class") == 'cont_box box s3')
				scroller = 'big';
			else
				scroller = 'small';
			
    		$('.scroll.'+scroller+'.up').css('backgroundImage','');
    		$('.scroll.'+scroller+'.down').css('backgroundImage','');
			});
	
	// start/stop scroller
	$('.scroll.down').mousedown(function(event){
			cont_h = $(this).parent().find(".cont_box").height() - $(this).parent().find(".inner_box").height();
			$(this).parent().find(".inner_box").animate({"scrollTop": "+="+cont_h+"px"}, cont_h * 3, 'linear');
    		})
    	.mouseup(function(event){
    		$(this).parent().find(".inner_box").stop();
			});
	
	$('.scroll.up').mousedown(function(event){
			cont_h = $(this).parent().find(".cont_box").height() - $(this).parent().find(".inner_box").height();
			$(this).parent().find(".inner_box").animate({"scrollTop": "-="+cont_h+"px"}, cont_h * 3, 'linear');
    		})
    	.mouseup(function(event){//alert($(box2).height() - $(box).height());
    		$(this).parent().find(".inner_box").stop();
			});
	// shop
	/*
	$('.but_green, .but_grey').hover(
		function () {
    		$(this).css('background','url(../img/special/'+ $(this).attr('class') +'_over.gif) repeat-x');
    		}, 
    	function () {
    		$(this).css('background','url(../img/special/'+ $(this).attr('class') +'.gif) repeat-x');
			});
	*/
	
	// DropDown
	$(".drop_title").click(function() {
		var idString = $(this).parent().attr("id");
		$("#menue_" + idString).slideToggle("fast");
		});
	
	$(".but_drop").mouseleave(function() {
		$(this).find(".hide").hide();
		});
	
	$("#menue_drop_1 div, #menue_drop_2 div").hover(function () {
		$(this).css({'background-color' : '#ebebeb'});
    	}, function () {
			$(this).css({'background-color' : ''});
		});
	
	$("#menue_drop_1 div, #menue_drop_2 div").click(function () {
		var idString = $(this).parent().attr("id");
		idString = idString.substr(6);
		$("#"+idString+" .drop_title").find(".drop_this").text($(this).text());
		$("#"+idString+" .drop_title").find(".hide_this").val($(this).text());
		$(this).parent().hide();
    	});
    
	// datepicker
	if(document.getElementById('date_1')){
		$(function() {
			$('.date').datepicker({showOn: 'button', buttonImage: '/img/special/calendar.gif', buttonImageOnly: true, dateFormat: 'dd.mm.yy', dayNamesMin: ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'], monthNames: ['Januar','Februar','März','April','Mai','Juni','Juli','August','September','Oktober','November','Dezember'] });
			});
		}
	
	$("#lightbox_img, #lightbox_but_l, #lightbox_but_r, #lightbox_s").hover(function () {
		$("#lightbox_but_l, #lightbox_but_r").show();
	    	}, function () {
		$("#lightbox_but_l, #lightbox_but_r").hide();
			});
			
	$(".blend2").hover(function () {
		$(this).find("div:first").show();
    	}, function () {
			$(this).find("div:first").hide();
		});
	
	$('#content_big, #scroll_l, #scroll_r').hover(
		function(){
			if(($('#move').width() + 300) > $(window).width())
	    		$('#scroll_l, #scroll_r').show();
    		}, 
    	function(){
    		$('#scroll_l, #scroll_r').hide();
			});
	
	$('#scroll_l').mousedown(function(event){
			move_w = $("#move").width();
    		$('#content_big').animate({scrollLeft: $("#content_big").offset().left}, move_w, 'swing');
    		})
    	.mouseup(function(event){
    		$('#content_big').stop();
			});
	
	$('#scroll_r').mousedown(function(event){
			move_w = $("#move").width();
	    	$('#content_big').animate({scrollLeft: move_w - $(window).width() + 310}, move_w, 'swing');
    		})
    	.mouseup(function(event){
    		$('#content_big').stop();
			});
	
	$('.start_teaser a').hover(
		function(){
			if(document.getElementById('supersize')){
		    	$('.start_teaser a').css('color','#000000');
		    	$('.start_teaser a img').attr('src', 'img/special/continue_hover.png');
		    	}
    		}, 
    	function(){
    		if(document.getElementById('supersize')){
	    		$('.start_teaser a').css('color','#ffffff');
    			$('.start_teaser a img').attr('src', 'img/special/continue_active.png');
    			}
			});
	
	$('.ticket').hover(
		function(){
	    	$(this).attr('src', 'img/special/ticket_hover.png');
    		}, 
    	function(){
    		$(this).attr('src', 'img/special/ticket_active.png');
			});
	});

// shop
function calculate(){
	var num = document.getElementById('amount').value;
	if(!isNaN(num)){
		num = num * document.getElementById('price').value;
		num = String(num.toFixed(2));
		var num_split = num.split('.');
		var new_num = num_split[0] + ',' + num_split[1].substr(0,2);
		document.getElementById('result').innerHTML = new_num;
		}
	}

function check_email(s){
	var a = false, res = false, reg;
	if(typeof(RegExp) == 'function'){
		var b = new RegExp('abc');
		if(b.test('abc') == true)
			a = true;
		}
	if(a == true){
		reg = new RegExp('^([a-zA-Z0-9\-\.\_]+)(\@)([a-zA-Z0-9\-\.]+)(\.)([a-zA-Z]{2,4})$');
		res = (reg.test(s));
		}
	else{
		res = (s.search('@') >= 1 && s.lastIndexOf('.') > s.search('@') && s.lastIndexOf('.') >= s.length-5)
		}
	return(res);
	}

function check_order(){
	var go = '1', shop_array = new Array('amount', 'firstname', 'lastname', 'email', 'street', 'number', 'zip', 'town', 'country');
	
	for(var i=0;i<shop_array.length;++i){
		document.getElementsByName(shop_array[i])[0].style.backgroundColor = '#ffffff';
		
		if(document.getElementsByName(shop_array[i])[0].value == ''){
			document.getElementsByName(shop_array[i])[0].style.backgroundColor = '#de0000';
			go = '2';
			}
		}
	
	if(document.getElementsByName('amount')[0].value == '0'){
		document.getElementsByName(shop_array[i])[0].style.backgroundColor = '#de0000';
		go = '2';
		}
	
	if(document.getElementsByName('ok')[0].checked == false){
		document.getElementById('ok_text').style.color = '#de0000';
		go = '2';
		}
	else
		document.getElementById('ok_text').style.color = '#ffffff';
	
	if(check_email(document.getElementsByName('email')[0].value) == false && go == '1'){
		document.getElementsByName('email')[0].style.backgroundColor = '#de0000';
		go = '3';
		}
	
	if(go == '1')
		document.send_order.submit();
	else{
		document.getElementById('shop_warning').style.display = 'block';
		if(go == '2')
			document.getElementById('shop_warning_text').innerHTML = 'Bitte das Formular vollständig ausfüllen!'
		else
			document.getElementById('shop_warning_text').innerHTML = 'Geben Sie bitte eine korrekte E-Mail Adresse an!'
		}
	}

function check_acc(){
	var go = '1', acc_array = new Array('firstname', 'lastname', 'company', 'email', 'phone', 'street', 'number', 'zip', 'town', 'country', 'date');
	
	for(var i=0;i<acc_array.length;++i){
		document.getElementsByName(acc_array[i])[0].style.backgroundColor = '#ffffff';
		
		if(document.getElementsByName(acc_array[i])[0].value == ''){
			document.getElementsByName(acc_array[i])[0].style.backgroundColor = '#de0000';
			go = '2';
			}
		}
	
	document.getElementById('drop_this_1').style.backgroundColor = '#aaaaaa';
	if(document.getElementsByName('branch')[0].value == 'Bitte wählen'){
		document.getElementById('drop_this_1').style.backgroundColor = '#de0000';
		go = '2';
		}
	
	document.getElementById('drop_this_2').style.backgroundColor = '#aaaaaa';
	if(document.getElementsByName('purpose')[0].value == 'Bitte wählen'){
		document.getElementById('drop_this_2').style.backgroundColor = '#de0000';
		go = '2';
		}
	
	if(document.getElementsByName('ok')[0].checked == false){
		document.getElementById('ok_text').style.color = '#de0000';
		go = '2';
		}
	else
		document.getElementById('ok_text').style.color = '#ffffff';
	
	if(check_email(document.getElementsByName('email')[0].value) == false && go == '1'){
		document.getElementsByName('email')[0].style.backgroundColor = '#de0000';
		go = '3';
		}
	
	if(go == '1')
		document.send_order.submit();
	else{
		document.getElementById('shop_warning').style.display = 'block';
		if(go == '2')
			document.getElementById('shop_warning_text').innerHTML = 'Bitte das Formular vollständig ausfüllen!'
		else
			document.getElementById('shop_warning_text').innerHTML = 'Geben Sie bitte eine korrekte E-Mail Adresse an!'
		}
	}

// preload
var img_array = new Array();
img_array[0] = "img/special/but_grey_over.gif";
img_array[1] = "img/special/but_green_over.gif";
img_array[2] = "img/special/twitter_on.png";
img_array[3] = "img/special/facebook_on.png";
img_array[4] = "img/special/yps_on.png";
img_array[5] = "img/special/vimeo_on.png";
img_array[6] = "img/special/continue_hover.png";
img_array[7] = "img/special/ticket_hover.png";

for(var i=0;i<img_array.length;i++){
	var img = new Image();
	img.src = img_array[i];
	}

// change img
function change_img(num, what, format){
	if(num == 1)
		document.getElementById(what).src = 'img/special/'+ what +'_over.'+ format;
	else
		document.getElementById(what).src = 'img/special/'+ what +'.'+ format;
	}

// change bg_img
function change_bg_img(where, what){
		document.getElementById(where).style.backgroundImage = "url(img/special/"+ what +")";
	}

// Tooltip
var mytip = null;

function update_tip(e){
	if(mytip){
		var x = (document.all) ? window.event.clientX : e.pageX;
		var y = (document.all) ? window.event.y + mytip.offsetParent.scrollTop : e.pageY;
		var dx = mytip.offsetWidth;
		
		if(document.body.clientWidth < dx + x + 15)
			mytip.style.left = (x - dx - 15) + 'px';
		else
			mytip.style.left = (x + 15) + 'px';
		mytip.style.top = (y + 15) + 'px';
		}
	}

function tip(text, len){
	if(text.length > len){
		mytip = document.getElementById('tooltip');
		mytip.style.display = 'block';
		mytip.innerHTML = text;
		document.onmousemove = update_tip;
		}
	}
 
function untip(){
	if(mytip)
		mytip.style.display = 'none';
	}
