$(document).ready(function(){




/* Slider Setup */
var flowheight = $(".firstslide").height();
jflowstart(flowheight);

$(".rightarrow, .leftarrow").css("top", flowheight/3);

function jflowstart(height) {
	$("#slidecontroller").jFlow({  
		slides: "#contentslider",  
		width: "100%",  
		height: height,  
		duration: 400,
	});  
}

$(window).resize(function(){
  $.doTimeout( 300, function(){
   
	var flowheight = parseInt($(".firstslide").height());
	$("#jFlowSlide").stop().animate({height: flowheight},100, "linear");
	$(".rightarrow, .leftarrow").stop().animate({top: flowheight/3},0, "linear");
  });
});


$(".jFlowControl").click(function() {
	$(".jFlowControl").removeClass("active");
	$(this).addClass("active");
});

/* Circle Controller */
var slidePos = 0;

$(".jFlowControl").click(function() {
	var btnIndex = $(this).index();
	slidePos = btnIndex;
});

$(".jFlowNext").click(function() {
	if (slidePos >= ($(".jFlowControl").length)-1)	{slidePos = 0}
	else {slidePos++;}
	$(".jFlowControl").removeClass("active");
	$(".jFlowControl:nth-child("+(slidePos+1)+")").addClass("active");
});

$(".jFlowPrev").click(function() {
	if (slidePos <= 0)	{slidePos = $(".jFlowControl").length;}
	slidePos--;
	$(".jFlowControl").removeClass("active");
	$(".jFlowControl:nth-child("+(slidePos+1)+")").addClass("active");
});
/* End Circle Controller */

$(document.documentElement).keydown(function(e){
    if (e.keyCode == 37) { 
       $('.jFlowPrev').trigger('click');
       return false;
    }
    if (e.keyCode == 39) { 
       $('.jFlowNext').trigger('click');
       return false;
    }
});

// Autoscroll
function autoscroll() {
	$.doTimeout('loop', 5000, function(){
		$('.jFlowNext').trigger('click');
		return true
	});
};
autoscroll();


$(".aufmacher").hover(
  function () {
    $.doTimeout( 'loop' );
  }, 
   function () {
    autoscroll();
  }
);

/* End Slider */




/* Fancybox Setup */


function fb (target) {
	$.fancybox({
		'href'			: target.href,
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'easingIn'		:	'swing',
		'easingOut'		:	'swing',
		'speedIn'		:	200, 
		'speedOut'		:	200,
		'changeSpeed'	:	100,
		'overlayShow'	:	true,
		'overlayOpacity':	'0.5',
		'overlayColor':	'#000',
		'hideOnOverlayClick'	:	true,
		'hideOnContentClick'	:	true
	});
}


$(".fancyvid").click(function() {
	$.fancybox({
			'padding'		: 0,
			'autoScale'		: false,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'title'			: this.title,
			'width'		: 640,
			'height'		: 480,
			'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
			'type'			: 'swf',
			'swf'			: {
			   	 'wmode'		: 'transparent',
				'allowfullscreen'	: 'true'
			},
	'overlayShow'	:	true,
	'overlayOpacity':	'0.5',
	'overlayColor':	'#000',
	'hideOnOverlayClick'	:	true,
	'hideOnContentClick'	:	false

		});

	return false;
});


$("a.fancypic, a[href$=.jpg],a[href$=.png],a[href$=.gif").click(function() {
	fb(this);
	return false;
});

// End FancyBox




// Animate Bars (Detailpage)

function animatebars() {
	$.each($(".bar"), function() {
	var length = $(this).attr("data-width")+"%";
	$(this).stop().animate({width: length},1000, "linear");
	});
};
animatebars();

$(".gear").click(function() {
	$(".bar").css("width", "0");
	animatebars();
});





// Startpage Thumbnail Hover Effect

$("ul.startthumbs li").mouseover(function() {
	$(this).find('.popupinfo').show();
	$(this).find('.popupinfo').stop().animate({height: 30},200, "swing");
});

$("ul.startthumbs li").mouseout(function() {
	$(this).find('.popupinfo').stop().animate({height: 0});
	$(this).find('.popupinfo').hide();
});



// Thumb Image Selecter
// HoverIntent
function doNothing() {};
var jsHoverMenuConfig = {
	 interval: 15,
	 sensitivity: 4,
	 over: thumbhover,
	 timeout: 0,
	 out: doNothing
};
// Hover Function Call
$(".tinythumb img").hoverIntent(jsHoverMenuConfig)

function thumbhover() {
	var picpath = $(this).attr("data-thumbtarget");
	var picalt = $(this).attr("alt");
	var title = $(this).attr("data-title");
	var link = $(this).attr("data-linktarget");
	var target = $(this).attr("data-target");

	$(".detailimage img").attr("src", picpath);
	$(".detailimage img").attr("alt", picalt);
	$(".detailimage a").attr("target", target);
	$(".detailimage a").attr("title", title);
	$(".detailimage a").attr("href", link);

	$(".tinythumb li").removeClass("active");
	$(this).parent().addClass("active");

	$(".detailimage").children().unbind();
	if (target == "_self") {
		$(".detailimage a").click(function() {
			fb(this);
			return false;
		});
	};


};
// End Thumb Image Selecter



// End Document Ready
});
