var intInteriorIndex = 0;
var intAntal = 0;

	$(document).ready(function(){ 
		$("div.storefloat1 img").click(function(){storeSetImage($(this).attr("rel"));});
		$("div.storefloat2 img").click(function(){storeSetImage($(this).attr("rel"));});
		$("div#arrright").click(function(){interiorNext();});
		$("div#arrleft").click(function(){interiorPrev();});
		$("div.tygfloat").click(function(){setTyg($(this).attr("id"));});
 	});

	$("div#imgids span").click(function(){interiorChosen($(this).attr("id"));});


	function setTyg(thisTyg) {
		$("#tygbottom div").each(function() {
			if ($(this).attr("id").substring(0,3) == "tyg") {
				$(this).css("display","none");
			}
		});
		$("#" + thisTyg + "-text").css("display","block");		
		$('#tygviewer').flash({swf: 'flash/' + thisTyg + '.swf', height: 346, width: 502}); 
	}


	function interiorCount() {
		intAntal = 0;
		$("#imgids").html("<img src='img/head/bild.gif' alt='' />");
		$("#imgcontainer img").each(function() {
			intAntal++;
			var currImgids = $("#imgids").html();
			if (intAntal == (intInteriorIndex)) {
				$("#imgids").html(currImgids + "<span onclick='interiorChosen(" + intAntal + ");' class='selected'>" + intAntal + "</span>")
			}
			else
			{
				$("#imgids").html(currImgids + "<span onclick='interiorChosen(" + intAntal + ");'>" + intAntal + "</span>")
			}
			
		});
	}

	function storeSetImage(thisImg) {
		$("#mainright").css('display', 'none'); 
		$("#mainright").html("<img src=\"http://cms.cmsoffice.se/img/kunder/5/bilder/" + thisImg + "\" />");
		$("#mainright").fadeIn();
	}
	
	
	function interiorChosen(thisImgId) {
		var imgId = thisImgId;
		intInteriorIndex = imgId;	
		interiorCount();
	
		thisId = "#imgcontainer";

		$(thisId+' img').css('display', 'none'); 
		$(thisId+' img:nth-child('+intInteriorIndex+')').fadeIn();
	}
	
	function interiorNext() {			
		intInteriorIndex++;	
		interiorCount();
	
		thisId = "#imgcontainer";

		if (intInteriorIndex > intAntal) {
			intInteriorIndex = 1;
			interiorCount();
		}
		$(thisId+' img').css('display', 'none'); 
		$(thisId+' img:nth-child('+intInteriorIndex+')').fadeIn();
	}
	
	function interiorPrev() {			
		intInteriorIndex = intInteriorIndex - 1;	
		interiorCount();
	
		thisId = "#imgcontainer";


		if (intInteriorIndex == 0) {
			intInteriorIndex = intAntal;
			interiorCount();
		}
		$(thisId+' img').css('display', 'none'); 
		$(thisId+' img:nth-child('+intInteriorIndex+')').fadeIn();
	}
