// JavaScript Document

$(document).ready(function()
{		
	function setBannerSlideshow() {
		var bannerChildCounter = 0;
		var bannerChildsArray = new Array();
		var bannerCurrent = 0;
		
		$(".bannerslideshow > .bannerslideshow_image").each(function(){
			bannerChildsArray[bannerChildCounter] = $(this);
			bannerChildCounter = bannerChildCounter + 1;
		});
		
		if (bannerChildCounter>1) {
			$(".bannerslideshow > .bannerslideshow_image:not(:first)").hide();
			//$(".bannerslideshow").append("<div class='bannerslideshow_prev'><div class='bannerslideshow_prev_background'></div><div class='bannerslideshow_prev_button'>&lt;</div></div>");
			$(".bannerslideshow").append("<div class='bannerslideshow_next'><div class='bannerslideshow_next_background'></div><div class='bannerslideshow_next_button'>&gt;</div></div>");
			//$(".slideshow_next").hide();
			//slideshow_interval = setTimeout(slideshow, 5000);
			//$(".bannerslideshow_prev").css({cursor: "pointer"}).hide();
			/*$(".bannerslideshow_prev").hover(function(){
				$(this).find(".bannerslideshow_prev_background").css({backgroundColor : "#CD2234"});									
			},function(){
				$(this).find(".bannerslideshow_prev_background").css({backgroundColor : "#FFFFFF"});	
			});*/
			$(".bannerslideshow_next").css({cursor: "pointer"}).hide();;
			$(".bannerslideshow_next").hover(function(){
				$(".bannerslideshow_next_background").css({opacity: 1});
				//$(this).find(".bannerslideshow_next_background").css({backgroundColor : "#ffc501"});									
			},function(){
				$(".bannerslideshow_next_background").css({opacity: 0.5});
				//$(this).find(".bannerslideshow_next_background").css({backgroundColor : "#FFFFFF"});	
			});
			$(".bannerslideshow_next_background").css({opacity: 0.5});
			//$(".bannerslideshow_prev_background").css({opacity: 0.5});
			/*$(".textpic_slideshow").hover(function(){
					$(".slideshow_next").show();						   
			}, function(){
				$(".slideshow_next").hide();	
			});*/
			
			$(".bannerslideshow_prev").click(function() {
				if (bannerCurrent-1>=0) {
					bannerChildsArray[bannerCurrent].fadeOut("def");
					bannerCurrent--;
					bannerChildsArray[bannerCurrent].fadeIn("def");
				} else {
					bannerChildsArray[bannerCurrent].fadeOut("def");
					bannerCurrent = bannerChildsArray.length-1;
					bannerChildsArray[bannerCurrent].fadeIn("def");
				}
			});
			
			$(".bannerslideshow_next").click(function() {
				if (bannerCurrent+1<bannerChildsArray.length) {
					bannerChildsArray[bannerCurrent].fadeOut("def");
					bannerCurrent++;
					bannerChildsArray[bannerCurrent].fadeIn("def");
				} else {
					bannerChildsArray[bannerCurrent].fadeOut("def");
					bannerCurrent = 0;
					bannerChildsArray[bannerCurrent].fadeIn("def");
				}
			});
			
			/*$(".slideshow").click(function(){
				if($(this).next().not(".slideshow_next").attr("class")!=undefined) {
					$(this).fadeOut("def");
					$(this).next().fadeIn("def");
				} else {
					$(this).fadeOut("def");
					$(".textpic_slideshow > .slideshow:first").fadeIn("def");
				}		   
			});*/
		}
		
		$(window).load(function(){
			$(".bannerslideshow .loading").remove();
			$(".bannerslideshow > .bannerslideshow_image:first").show();
			$(".bannerslideshow_next").show();
			$(".bannerslideshow_prev").show();
		});
	}

	function setSlideshow() {
		var childCounter = 0;
		var childsArray = new Array();
		var current = 0;
		
		$(".slideshow > .slideshow_image").each(function(){
			childsArray[childCounter] = $(this);
			childCounter = childCounter + 1;
		});
		
		if (childCounter>1) {
			$(".slideshow > .slideshow_image:not(:first)").hide();
			$(".slideshow").append("<div class='slideshow_prev'><div class='slideshow_prev_background'></div><div class='slideshow_prev_button'>&lt;</div></div>");
			$(".slideshow").append("<div class='slideshow_next'><div class='slideshow_next_background'></div><div class='slideshow_next_button'>&gt;</div></div>");
			//$(".slideshow_next").hide();
			//slideshow_interval = setTimeout(slideshow, 5000);
			$(".slideshow_prev").css({cursor: "pointer"}).hide();
			$(".slideshow_prev").hover(function(){
				$(this).find(".slideshow_prev_background").css({backgroundColor : "#E3001A"});									
			},function(){
				$(this).find(".slideshow_prev_background").css({backgroundColor : "#EFAB32"});	
			});
			$(".slideshow_next").css({cursor: "pointer"}).hide();;
			$(".slideshow_next").hover(function(){
				$(this).find(".slideshow_next_background").css({backgroundColor : "#E3001A"});									
			},function(){
				$(this).find(".slideshow_next_background").css({backgroundColor : "#EFAB32"});	
			});
			//$(".slideshow_next_background").css({opacity: 0.75});
			/*$(".textpic_slideshow").hover(function(){
					$(".slideshow_next").show();						   
			}, function(){
				$(".slideshow_next").hide();	
			});*/
			
			$(".slideshow_prev").click(function() {
				if (current-1>=0) {
					childsArray[current].fadeOut("def");
					current--;
					childsArray[current].fadeIn("def");
				} else {
					childsArray[current].fadeOut("def");
					current = childsArray.length-1;
					childsArray[current].fadeIn("def");
				}
			});
			
			$(".slideshow_next").click(function() {
				if (current+1<childsArray.length) {
					childsArray[current].fadeOut("def");
					current++;
					childsArray[current].fadeIn("def");
				} else {
					childsArray[current].fadeOut("def");
					current = 0;
					childsArray[current].fadeIn("def");
				}
			});
			
			/*$(".slideshow").click(function(){
				if($(this).next().not(".slideshow_next").attr("class")!=undefined) {
					$(this).fadeOut("def");
					$(this).next().fadeIn("def");
				} else {
					$(this).fadeOut("def");
					$(".textpic_slideshow > .slideshow:first").fadeIn("def");
				}		   
			});*/
		}
		
		$(window).load(function(){
			$(".slideshow .loading").remove();
			$(".slideshow > .slideshow_image:first").show();
			$(".slideshow_next").show();
			$(".slideshow_prev").show();
		});
	}
	
	/* actions */
	
	setBannerSlideshow();
	setSlideshow();
});
