$(document).ready(function (){
	
	// keep IE from throwing errors on console.log
	
	if(!window.console) {
		window.console = {
				log: function (str) {
					// alert(str); // keep commented
			}
		};
	}
	
	$('#toolbar').tstoolbar();
	
	$('#categories').css('height', $('#contentRight').outerHeight(true));
	
	$("li.aspect, ul.accordion h3, .next, .prev, .play_vid, #fake_search, #search_form_small, li.problem, .accordionButton, .close_guarantee, .close_icon, #categorySelect li a, li.premiumShop, span.icon_arrow_right_blue, div.teaser_box, li.startClaimAbuse")
	.mouseover(function (){
		$(this).addClass('over');
	})
	.mouseout(function (){
		$(this).removeClass('over');
	});
	
	$('li', $('#language'))
	.mouseover(function (){
		$(this).addClass('over');
	})
	.mouseout(function (){
		$(this).removeClass('over');
	})
	.not('.multilang').click(function () {
		window.location.href = $('a', $(this)).attr('href');
	});
	
	$('#search_form_small button').mouseover(function() {
		$(this).parents('form').children('input').addClass('over');
	});
	
	$(".spb, .lpb").live('mouseover', function() {
		$(this).addClass('over');
	}).live('mouseout', function () {
		$(this).removeClass('over');
	});
	
	$("div.teaser_box").click(function () {
		if($(this).hasClass("search_box")) {
			$('input', $(this)).trigger('focus');
			return;
		}	
		$("a:visible", $(this)).trigger('click');
	});
	
	$("div.teaser_box a").click(function (e) {
		window.location.href = $(this).attr('href');
		e.stopPropagation();
	});
	
	$("li.aspect").click(function(e){
		$("a:first", $(this)).click();
	});
	
	$("li.premiumShop").live('click', function(){
		if($(this).hasClass('anchor')) {
			return false;
		}
		var shopUrl = $(this).children('a').attr('href');
		window.location.href = shopUrl;
	});
	
	$("a", ".aspect").click(function (event) {
		var name = $(this).attr("href").slice(1);
		switch (name){
			case "first_aspect":
			duration=300;
			break;
			case "second_aspect":
			duration=400;
			break;
			case "third_aspect":
			duration=500;
			break;
			case "fourth_aspect":
			duration=600;
			break;
			case "fifth_aspect":
			duration=700;
			break;
			case "sixth_aspect":
			duration=800;
			break;
			default:
			duration=600;
			break;	
		}
		event.preventDefault();
		$('html, body').animate({scrollTop: $('#' + name).parents("div.content_box").offset().top}, duration);
		return false;
	});
	
	$(".anchor_top").click(function () {
		$('html,body').animate({
			scrollTop: '0'
		}, 500);
		return false;
	});
	
	$("ul.accordion").accordion({
		autoHeight: false,
		collapsible: true,
		active: false
	});


	$('#slides').slides({
		width: 400,
		height: 322,
		preload: true,
		playInterval: 5000,
		pauseInterval: 5000,
		hoverPause: true,
		startAtSlide: 0,
		bigTarget: true,
		navigateStart: function(current){
			
		},
		navigateEnd: function(current){
			
		}
	});
	
	$("#slides").slides("play");

	$('div.security_stage').slides({
		width: 780,
		height: 464,
		pagination: false
	});
	
	$('a.play_vid').click(function (){
		
		var elem = $(this);
		
		$('a.slidesPrevious, a.slidesNext', $('div.security_stage')).click(function (){
			removeVid();
		});
		
		function removeVid() {
			if($('#ytplayer').length > 0) { 
				$('#ytplayer').parents('div.video').children().show();
				$('#ytplayer').remove();	
			}
		}
		
		function insertVid() {
			elem.parents('div.video').children().hide();
			elem.parents('div.video').append('<div id="ytplayer"></div>');
			var videoID = elem.attr('id').replace("video_", "");
			
			$("#ytplayer").append('<div id="mijsvdiv' + videoID + '"></div><div></div>');

			var script = document.createElement( 'script' );
			script.type = 'text/javascript';
			script.src = 'http://www.movingimage24.com/videojs_' + videoID + '?jsdiv=mijsvdiv' + videoID + '&width=780&height=464&player=v2&scwm=2&adbtn=0&adbtn1=0&adbtn3=0&adbtn5=0&chapter=0&overlays=0&cbarPlayPauseFlag=1&cbarTrackFlag=1&cbarTimeTotalFlag=0&cbarTimeDurationFlag=0&cbarvolumeBarFlag=0&volumeBtn=1&cbarFullScreenFlag=1&qs=1&bg=0cafcc&bg2=0dbedc&ctlstyle=none&fg=FFFFFF&ctcb1=FFFFFF&ctcb2=FFDC0F&ctcb3=FFDC0F&ctcb4=FFFFFF&ctcb5=FFFFFF&ctcb6=CCE300&ctcb7=FFDC0F&ctg1=FFFFFF&ctg2=FFDC0F&ctg3=DAd9D5&ctg4=363833&ctg5=60&ctab1=FFFFFF&ctab2=FFDC0F&ctab3=FFDC0F&ctab4=999999&ctab5=FFDC0F&ctab6=DAd9D5&sbg=FFFFFF&pbg=FFFFFF&wvm=2&start=1&volume=70&thumbasfs=0&loadtime=0&wmode=opaque&fupdate=1&cwm=0&ctp=0&plang=de&qd';
			$("#ytplayer").append( script );
			
			
		}
		
		removeVid();
		insertVid();
	});


//	Gurantee Box open/close
	
		var guaranteeButton = $('.accordionButton');
		var guaranteeConditions = $('.accordionContent');
		
		guaranteeConditions.hide();
		
		guaranteeButton.click(function () {
		if(guaranteeConditions.is(':hidden') == true) {
				$(this).text('Bedingungen für die Trusted Shops Garantie ▲');
				guaranteeConditions.slideDown();
		} else {
			$(this).text('Bedingungen für die Trusted Shops Garantie ▼');
			guaranteeConditions.slideUp();
		} 
		
		$('.close_guarantee').click(function () {
			guaranteeConditions.slideUp();
			guaranteeButton.text('Bedingungen für die Trusted Shops Garantie ▼');
		});
		
		});

	$(".fancybox").fancybox();
	
	$('li.problem').click(function () {
		$('a.fancybox_inline', $(this)).click();
	});
	
	$("a.fancybox_inline").click(function (e) {
		e.stopPropagation();	
	});

	$(".fancybox_inline").fancybox();

});
