var anim = false;
var outanim = true;

function menu(){
	$("#menu ul li.main").mouseenter(function() {
	
		if($(this).children().length > 1){
			if(!$(this).hasClass("active") && !$(this).hasClass("sfhover")){
				$(this).addClass("sfhover");
			}
		} else {
			if(!$(this).hasClass("active") && !$(this).hasClass("hover")){
				$(this).addClass("hover");
			}
		}
		
	}).mouseleave(function(){

		if($(this).children().length > 1){
			$(this).removeClass("sfhover");
		} else {
			$(this).removeClass("hover");
		}
		
		
	});
}

function gotoLink(htmlElement) {
	
	var destinationURL = "";
	var target = "";
	
	if(htmlElement.href) {
		destinationURL = htmlElement.href;
		target = htmlElement.getAttribute("target");
	}
	else {
		if(htmlElement.childNodes) {
			if(htmlElement.getElementsByTagName("a")) {
				destinationURL = htmlElement.getElementsByTagName("a")[0].href;
				target = htmlElement.getElementsByTagName("a")[0].getAttribute("target");
			}
		}
	}

	
	if(destinationURL.length > 0) {
		if(target == "_blank") {
			window.open(destinationURL);
		}
		else {
			location.href = destinationURL;
		}
	}
	return false;
}


function country(){
	$("#country").mouseenter(function() {

		if(!$(this).hasClass("sfhover")){
			$(this).addClass("sfhover");
			$(this).css("background-position","0 -187px");
		}
		
	}).mouseleave(function(){
		$(this).removeClass("sfhover");
		$(this).css("background-position","0 -145px");

	});
}

function resize(){
	$(window).resize(function() {
		if($(document).width() <= 990){
			$('body').css("background-position","-500px top");
		} else {
			$('body').css("background-position","center top");
		}
	});
}

function newsteaser(){

	$(".newsteaser").mouseenter(function() {
		$(this).css("background-position","0 -139px");
		$(this).find('a').css("background-position","-195px -1px");
		$(this).find('a').css("color","#821e32");
		
	}).mouseleave(function(){
		$(this).css("background-position","0 0");
		$(this).find('a').css("background-position","-195px -18px");
		$(this).find('a').css("color","#3a2e2a");
	});
}

function mycarousel_initCallback(carousel){
    // Disable autoscrolling if the user clicks the prev or next button.
   /* carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });*/

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};


function teaserswitch(){

	navig = 1;
	news = $('.teaserwrapperinlay').find('.switcher').length;
	news = news*200;
	$('.teaserwrapperinlay').css("width",news+"px");

	pos = 0;
	picwidth = 200;
	
	end = (news-picwidth)*-1;

	//setInterval ( "autoteaserswitch()", 1000 );
	
	$('#nextsw').click(function() {
		//end = (news-200)*-1;
		if(pos != end){
			pos = pos - picwidth;

			$('.teaserwrapperinlay').animate({
				marginLeft: pos+"px"
			}, 500, function() {
				// Animation complete.
				navig = navig+1;
				$('#backsw').css("background-position","0 -11px");
				$('#backsw').css("cursor","pointer");
				if(pos == end){
					$('#nextsw').css("background-position","-7px -11px");
					$('#nextsw').css("cursor","auto");
				}
				newhtml = $('.textinlay_'+navig).html();
				$('#txt').html(newhtml);
			});
		}
	});

	$('#backsw').click(function() {

		if(pos != 0){
			pos = pos + picwidth;

			$('.teaserwrapperinlay').animate({
				marginLeft: pos+'px'
			}, 500, function() {
				// Animation complete.
				navig = navig-1;
				$('#nextsw').css("background-position","-7px 0");
				$('#nextsw').css("cursor","pointer");
				if(pos == 0){
					$('#backsw').css("background-position","0 0");
					$('#backsw').css("cursor","auto");
				}
				newhtml = $('.textinlay_'+navig).html();
				$('#txt').html(newhtml);
			});
		}
	});


}


function autoteaserswitch(){
console.log("sw");
	$('.teaserwrapperinlay').animate({
		marginLeft: pos+"px"
	}, 500, function() {
		// Animation complete.
		navig = navig+1;
		$('#backsw').css("background-position","0 -11px");
		$('#backsw').css("cursor","pointer");
		if(pos == end){
			$('#nextsw').css("background-position","-7px -11px");
			$('#nextsw').css("cursor","auto");
		}
		newhtml = $('.textinlay_'+navig).html();
		$('#txt').html(newhtml);
	});
}


function fancyvideo(link, file){
	$.fancybox({
	    'padding'           : 0,
        'autoScale'     	: false,
		'width'     		: 800,
		'height' 			: 484,
		'transitionIn'	    : 'elastic',
		'transitionOut'	    : 'elastic',
		'type'				: 'swf',
		'href'				: link,
		'swf'            	: {
			'flashvars': 'videoSrc='+file,
			'wmode'		: 'transparent'

		} 

	});
}

function fancytip(link){
	$.fancybox({
		'padding'       : 0,
		'href'			: link,
		'width'			: 560,
		'height'		: 540,
		'type'			: 'iframe'
	});
}

function box(){
	$(".pic a").fancybox({
		'padding'       : 0,
		'titleShow'     : false,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic'
	});
	
	$(".pic2 a").fancybox({
		'padding'       : 0,
		'titleShow'     : false,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic'
	});
	
	$(".rightimages a").fancybox({
		'padding'       : 0,
		'titleShow'     : false,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic'
	});
	
	$(".leftimages a").fancybox({
		'padding'       : 0,
		'titleShow'     : false,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic'
	});
	
	$("a.tip").fancybox({
		'padding'       : 0,
		'href'			: this.href,
		'width'			: 560,
		'height'		: 540,
		'type'			: 'iframe'
	});
	
	$("a.tiplink").fancybox({
		'padding'       : 0,
		'href'			: this.href,
		'width'			: 560,
		'height'		: 540,
		'type'			: 'iframe'
	});

	$("a.bttolbox").fancybox({
		'padding'       : 0,
		'href'			: this.href,
		'width'			: 560,
		'type'			: 'ajax'
	});
	
}

function buttons(){
	$(".btn").mouseenter(function() {
		$(this).find('.btnleft').css("background-position","0px -71px");
		$(this).find('.btnright').css("background-position","right -71px");
		
	}).mouseleave(function(){
		$(this).find('.btnleft').css("background-position","0px -48px");
		$(this).find('.btnright').css("background-position","right -48px");
	});
	
	$(".btn2").mouseenter(function() {
		$(this).find('.btnleft').css("background-position","0px -71px");
		$(this).find('.btnright').css("background-position","right -71px");
		
	}).mouseleave(function(){
		$(this).find('.btnleft').css("background-position","0px -48px");
		$(this).find('.btnright').css("background-position","right -48px");
	});
	
	
	$(".btnprint").mouseenter(function() {
		$(this).find('.btnleft').css("background-position","0px -71px");
		$(this).find('.btnright').css("background-position","right -117px");
		
	}).mouseleave(function(){
		$(this).find('.btnleft').css("background-position","0px -48px");
		$(this).find('.btnright').css("background-position","right -94px");
	});
	
	$(".btnsend").mouseenter(function() {
		$(this).find('.btnleft').css("background-position","0px -71px");
		$(this).find('.btnright').css("background-position","right -163px");
		
	}).mouseleave(function(){
		$(this).find('.btnleft').css("background-position","0px -48px");
		$(this).find('.btnright').css("background-position","right -140px");
	});
	
	$(".btndownload").mouseenter(function() {
		$(this).find('.btnleft').css("background-position","0px -71px");
		$(this).find('.btnright').css("background-position","right -71px");
		
	}).mouseleave(function(){
		$(this).find('.btnleft').css("background-position","0px -48px");
		$(this).find('.btnright').css("background-position","right -48px");
	});
	
	$(".cartpic").mouseenter(function() {
		$(this).find('.cartdel').css("display","block");
		
	}).mouseleave(function(){
		$(this).find('.cartdel').css("display","none");
	});
	
	
	
	$(".submit2").mouseenter(function() {
		$(this).prev().find('.btnleft').css("background-position","0px -71px");
		$(this).prev().find('.btnright').css("background-position","right -71px");
		
	}).mouseleave(function(){
		$(this).prev().find('.btnleft').css("background-position","0px -48px");
		$(this).prev().find('.btnright').css("background-position","right -48px");
	});
	
	
	$(".picteaser").mouseenter(function() {
		$(this).css("background","#f4f2e5");

		
	}).mouseleave(function(){
		$(this).css("background","none");
	});
	
	
	
	$("a.next").mouseenter(function() {
		$(this).css("background-position","-25px -186px");
	}).mouseleave(function(){
		$(this).css("background-position","-25px 0px");
	});
	
	$("a.prev").mouseenter(function() {
		$(this).css("background-position","0 -209px");
	}).mouseleave(function(){
		$(this).css("background-position","0px -23px");
	});
	
	$(".rightimages").mouseenter(function() {
		$(this).find("span.lupe").css("background-position","-90px -255px");
	}).mouseleave(function(){
		$(this).find("span.lupe").css("background-position","-90px -229px");
	});
	
	$(".leftimages").mouseenter(function() {
		$(this).find("span.lupe").css("background-position","-90px -255px");
	}).mouseleave(function(){
		$(this).find("span.lupe").css("background-position","-90px -229px");
	});
	
	$(".pic").mouseenter(function() {
		$(this).find("span.lupe").css("background-position","-90px -255px");
	}).mouseleave(function(){
		$(this).find("span.lupe").css("background-position","-90px -229px");
	});
	
	$(".pic2").mouseenter(function() {
		$(this).find("span.lupe").css("background-position","-90px -255px");
	}).mouseleave(function(){
		$(this).find("span.lupe").css("background-position","-90px -229px");
	});
	
	
	
	$(".bttolbox").mouseenter(function() {
		$(this).css("background-position","0px -71px");
		$(this).next().css("background-position","right -71px");
	}).mouseleave(function(){
		$(this).css("background-position","0px -48px");
		$(this).next().css("background-position","right -48px");
	});

    $(".bttolbox2").mouseenter(function() {
		$(this).css("background-position","0px -71px");
		$(this).next().css("background-position","right -71px");
	}).mouseleave(function(){
		$(this).css("background-position","0px -48px");
		$(this).next().css("background-position","right -48px");
	});



    $('.faqquestion').find('a').click(function() {
        theclass = '.'+$(this).attr('id');
        scrollWin(theclass);
    });


    $(window).scroll(function () {
        $('#uplink').css('display', 'block');
    });
    
    $(window).resize(function() {

        if($(window).width() > 1200){
            pos = $(window).width() - 1200;
            $('#uplink').css('left', pos+'px');
        }
    });
}

function scrollWin(tg){

    $('html, body').animate({
        scrollTop: $(tg).offset().top
    }, 1000, function() {
        if($(tg).offset().top < 110){
            $('#uplink').css('display', 'none');
        } else {
            $('#uplink').css('display', 'block');
        }

        //nheight = ($(tg).offset().top+$(tg).height()-30);
       // $('#uplink').css('top', nheight+'px');
    });


}

function addItem (assteid,language) {
	$.ajax({
		type: "POST",
		url: "/?controller=Objects&action=additem",
		data: "assteid="+assteid+"&mode=add&lang="+language,
		success: function(msg){
			$('.cart').html(msg);
		}
	});
}

function removeItem (assteid,language) {
	$.ajax({
		type: "POST",
		url: "/?controller=Objects&action=additem",
		data: "assteid="+assteid+"&mode=remove&lang="+language,
		success: function(msg){
			$('.cart').html(msg);
		}
	});
}

function setflashteaser(){

	if($('#movie').length == 1){
		$(window).resize(function() {
			
			if($(window).height() < '690'){
				newheight = $(window).height() - 290;
				$('#movie').css("top", newheight+"px");
			}
		});
		
		if($(window).height() < '690'){
			newheight = $(window).height() - 290;
			$('#movie').css("top", newheight+"px");
		}
		
	}
}

function startelslider(){
    $(".contentblock.slider").elSlider({
        visibleitems        :   1,
        vertical            :   false,
        continuous          :   true,
        animationspeed      :   300,
        numbers				:	true,
        thumbs				:	true,
        fadingspeed			:	200,
        autoplay			:	true,
        autoplayspeed		:	4000
    });
}

function slideseries(){

    $(".shortseries").mouseenter(function(){
        mdiv = $(this).find(".movediv");

        $(mdiv).animate({
            top: 0
        }, 300, function() {

        });
    }).mouseleave(function(){

        mdiv = $(this).find(".movediv");

        $(mdiv).animate({
            top: 130
        }, 300, function() {
            anim = false;
        });
 
    });



}

function productionslide(){

    $(".nb").hover(function(){

        $(".steps").css("display","none");
        $(".contentdiv").css("display","none");

        if($(this).attr("id") == 'number_1'){
            $("#step_1").css("display","block");
            $("#ct_1").css("display","block");
        }

        if($(this).attr("id") == 'number_2'){
            $("#step_2").css("display","block");
            $("#ct_2").css("display","block");
        }

        if($(this).attr("id") == 'number_3'){
            $("#step_3").css("display","block");
            $("#ct_3").css("display","block");
        }

        if($(this).attr("id") == 'number_4'){
            $("#step_4").css("display","block");
            $("#ct_4").css("display","block");
        }

        if($(this).attr("id") == 'number_5'){
            $("#step_5").css("display","block");
            $("#ct_5").css("display","block");
        }

        if($(this).attr("id") == 'number_6'){
            $("#step_6").css("display","block");
            $("#ct_6").css("display","block");
        }

        if($(this).attr("id") == 'number_7'){
            $("#step_7").css("display","block");
            $("#ct_7").css("display","block");
        }

    });

}



function fbslideSwitch() {
    var $active = $('#fbportal .switchcontent .fbswitcher.active');
    var $activenav = $('.switchnav span.active');

    if ( $active.length == 0 ) $active = $('#fbportal .switchcontent .fbswitcher:last');
    if ( $activenav.length == 0 ) $activenav = $('.switchnav span:last');

    var $next =  $active.next().length ? $active.next() : $('#fbportal .switchcontent .fbswitcher:first');
    var $nextnav =  $activenav.next().length ? $activenav.next() : $('.switchnav span:first');

    $active.addClass('last-active');
    $activenav.addClass('last-active');

    $('#fbportal .switchcontent .fbswitcher').css({opacity: 0.0});

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });

    $nextnav.addClass('active');
    $activenav.removeClass('active last-active');

}


function fbstay(act){
    clearInterval(fbint);
    $('.switchnav span.active').removeClass('active last-active');
    $(act).addClass('active');

    indexsize = $(act).index();

    $('#fbportal .switchcontent .fbswitcher').css({opacity: 0.0});
    $('#fbportal .switchcontent .fbswitcher.active').removeClass('active last-active');
    $('#fbportal .switchcontent .fbswitcher:eq(' + indexsize + ')').addClass('active');
    $('#fbportal .switchcontent .fbswitcher:eq(' + indexsize + ')').animate({opacity: 1.0}, 1000, function() {
        //$('#fbportal .switchcontent .fbswitcher.active').removeClass('active last-active');
    });

}





$(document).ready(function() {
	menu();
	country();
	resize();
	//newsteaser();
	box();
	buttons();

	setflashteaser();
	slideseries();


    if ( $(".fbswitcher").length > 0 ) {
        $('#fbportal .switchcontent .fbswitcher').css({opacity: 0.0});
        $('#fbportal .switchcontent .fbswitcher.active').css({opacity: 1.0});

        fbint = setInterval( "fbslideSwitch()", 5000 );

        $('.switchnav span').click(function() {
            fbstay(this);
        });

        $(window).resize(function() {

            if($(window).height() < '690'){
                newheight = $(window).height() - 313;
                $('#fbportal').css("top", newheight+"px");
            }
        });

        if($(window).height() < '690'){
            newheight = $(window).height() - 313;
            $('#fbportal').css("top", newheight+"px");
        }


    }

    if ( $(".contentblock.slider").length > 0 ) {
        startelslider();
    }

    if ( $(".production").length > 0 ) {
        productionslide();
    }
	
	
});




