$(document).ready(function() {
	var diastripe = $("#imageSpanner");
	var width = diastripe.width();
	var scroll = true;
	var animOverlay = true;
	var imgWidth = 450;
	var shopBtn = true;

	// TOPNAVI HACK //
	//$("#headerNavi li a span").wrap("<p class=\"left\"></p>")
	
	$("#conRight").mouseover(function() {
		$("#picOverlay").stop();
		$("#picOverlay").animate( { top: "335px" } , 300);
	} );
	$("#conRight").mouseout(function() {
		$("#picOverlay").stop();
		$("#picOverlay").animate( { top: "370px" } , 300);
	} );

	$(".picControlLft a").click(function() {
		if(scroll) {
			scroll = false;
			var xpos = diastripe.css("left");
			xpos = xpos.replace(/px/g, "");
			xpos = parseFloat(xpos) + imgWidth;
			if(xpos == 0)
				$(".picControlLft").addClass("hidden");
			if(xpos > (width - imgWidth) * -1)
				$(".picControlRght").removeClass("hidden");
			diastripe.animate( { left: xpos+"px" } , 500, function() { scroll = true; } );
			var imgNr = xpos * (-1) / imgWidth;
			var newText = $("#imageSpanner img:eq("+imgNr+")").attr("alt");
			$("#picOverlay p").text(newText);
		}
	} );
	$(".picControlRght a").click(function() {
		if(scroll) {
			scroll = false;
			var xpos = diastripe.css("left");
			if(xpos == "auto")
				xpos = "0px";
			xpos = xpos.replace(/px/g, "") - imgWidth;
			if(xpos <= -imgWidth)
				$(".picControlLft").removeClass("hidden");
			if(xpos <= (width - imgWidth) * -1)
				$(".picControlRght").addClass("hidden");
			diastripe.animate( { left: xpos+"px" } , 500, function() { scroll = true; } );
			var imgNr = xpos * (-1) / imgWidth;
			var newText = $("#imageSpanner img:eq("+imgNr+")").attr("alt");
			$("#picOverlay p").text(newText);
		}
	});
	
	$("#shopBtn a").click(function() {
		if(shopBtn)
		{
			shopBtn = false;
			var name = $("#shopBtn #name").val();
			var preis = $("#shopBtn #preis").val();
			var crypt = $("#shopBtn #crypt").val();
			
			$("#shopBtn a").fadeOut("fast");
			
			$.post("index.php?ajax=shop", { name: name, preis: preis, crypt: crypt },
				function(data){
					if(data == "NOT OK") {
						alert("Leider ist ein Fehler aufgetreten, bitte versuchen Sie es erneut!");
						$("#shopBtn a").fadeIn("fast");
					}
					else
					{
						alert(name + " wurde dem Warenkorb hinzugefügt.");
						$("#shopBtn a img").attr("src","/cms/templates/raum_kreativ/images/rk_shopKorb.gif");
						$("#shopBtn a img").attr("alt","Zum Warenkorb");
						$("#shopBtn a").attr("title","Zum Warenkorb");
						$("#shopBtn a").attr("href","/cms/index.php?option=com_dfcontact&Itemid=15");
						$("#shopBtn a").attr("onclick","");
						$("#shopBtn a").fadeIn("normal");
					}
					shopBtn = true;
			});

			
		}
	});
});

function startDiashow(milsec)
{
	if(milsec)
		setInterval("scrollRight()",milsec*1000);
	else
		setInterval("scrollRight()",5000);
}
function scrollRight()
{
	var diastripe = $("#imageSpanner");
	var width = diastripe.width();
	var scroll = true;
	var animOverlay = true;
	var imgWidth = 450;
	
	if(scroll) {
		scroll = false;
		var xpos = diastripe.css("left");
		if(xpos == "auto")
			xpos = "0px";
		xpos = xpos.replace(/px/g, "") - imgWidth;
		
		if(xpos < (width - imgWidth) * -1)
			xpos = 0;

		diastripe.animate( { left: xpos+"px" } , 500, function() { scroll = true; } );
		var imgNr = xpos * (-1) / imgWidth;
		var newText = $("#imageSpanner img:eq("+imgNr+")").attr("alt");
		$("#picOverlay p").text(newText);
	}
}

$(function() {
	var lang = "de";
	if(lang == "en")
	{
		txtImg = "Image";
		txto	= "of";
	}
	else
	{
		txtImg = "Bild";
		txto	= "von";
	}
	var settings = jQuery.extend({
		overlayBgColor: 		'#000',
		overlayOpacity:		0.85,
		fixedNavigation:		false,
		imageLoading:			'/cms/templates/conelly_design/images/loader.gif',
		imageBtnPrev:			'/cms/templates/conelly_design/images/lightbox-btn-prev-'+lang+'.gif',
		imageBtnNext:			'/cms/templates/conelly_design/images/lightbox-btn-next-'+lang+'.gif',
		imageBtnClose:		'/cms/templates/conelly_design/images/lightbox-btn-close-'+lang+'.gif',
		imageBlank:			'/cms/templates/conelly_design/images/lightbox-blank.gif',
		containerBorderSize:		10,
		containerResizeSpeed:	400,
		txtImage:			txtImg,
		txtOf:				txto,
		keyToClose:			'c',
		keyToPrev:			'p',
		keyToNext:			'n',
		imageArray:			[],
		activeImage:			0
	},settings);

	$("#imageHolder a").lightBox(settings);
	$("#imageSpanner a").lightBox(settings);
});
