$(document).ready(function(){

	// Init
	$("#nav li li:first-child").css("border-top", "solid 1px #747A80");
 	$("#nav li ul li:has(ul)").find("a:first").append("<span class=\"arrow\">&raquo;</span>");
	
	$("#nav li li").click(function(e){ document.location = this.firstChild; });
		
	$("#nav a:not(:only-child)").unbind('click').click(function(e){ e.preventDefault(); });
	$("#nav li:has(ul)").unbind('click').click(function(e){ e.preventDefault(); });
	

 	$("#lang").hoverIntent(function(){},function(){});
 	$("#lang ul").css("display", "block");
	$("#lang li:first-child").css("border-top", "none");
	$("#lang ul").css("top", "0px");
	$("#lang li").click(function(e){ document.location = this.firstChild; });



	// Bildspel, startsida
	$("#defaultSlide").cycle({fx:'fade',timeout: 5000});
	
	// Bildspel, startsida
	$("#retailerSlide").cycle({fx:'fade',timeout: 5000});
	

	// Bildspel, introsida
	$('#introSlide').after('<div id="introSlideNav">').cycle({
        fx:     'fade',
        timeout: 5000,
        pager:  '#introSlideNav',
        pagerAnchorBuilder: function(idx, slide) {
            return '<a href="#"><img src="' + slide.firstChild.src + '" width="50" height="30" /></a>';
        }
    });	
	
	
	// Bildspel, tillbehör
	$('#tillbehorSlide').after('<div id="tillbehorSlideNav">').cycle({
        fx:     'fade',
        timeout: 5000,
        pager:  '#tillbehorSlideNav',
        pagerAnchorBuilder: function(idx, slide) {
            return '<a href="#"><img src="' + slide.firstChild.src + '" width="50" height="30" /></a>';
        }
    });
	
	// Navigation, produktsida
	$("ul#prodNav li").fadeTo(0, 0.5);
	$("ul#prodNav li").hoverIntent(function() { $(this).fadeTo(200, 1); }, function() { $(this).fadeTo(200, 0.5); });


	// Arkitektbildspel
 	$("ul.architectSlide .architectPost").css("display", "none");
 	$("ul.architectSlide .architectPost:first").css("display", "block");
	$("ul.architectSlide .images").cycle({fx:'fade',timeout: 5000});
	$("ul#architectNav a").click(function(e){
	var idx = $("ul#architectNav a").index(this);
 	$("ul.architectSlide .architectPost").css("display", "none");
 	$("ul.architectSlide .architectPost").eq(idx).css("display", "block");
	
	e.preventDefault();

	});
	
	// Bildhantering, produktsida
	$("#productsImages > a").click(function(e) { 
		var largeTarget = this + ""; 
		var mediumTarget = largeTarget.replace(/large/i, "medium"); 
		$("#productsImages > a:first").attr("href", largeTarget);
		$("#productsImages > a:first img").attr("src", mediumTarget);
		Shadowbox.setup();
		e.preventDefault();
	});
	
	// Katalogåterförsäljare
	$("form#catalogue select").change(function() { 
		document.location = this.value;
	});
	
	
	function factDynamics(idx) {
		var factMainMax = $('#factMain li').length;
		if (idx == factMainMax -1) {$("#next").text("1");} else {$("#next").text(idx+1);} 
		if (idx < 2) {$("#prev").text(factMainMax-1);} else {$("#prev").text(idx-1);}
	}
	
	// Bildspel, argumentsida
	$("#fact").after("<div id=\"factSlideNav\">").cycle({
        fx:     'scrollHorz',
	    speed:  'fast', 
        timeout: 0,
        pager:  '#factSlideNav',
	    next:   '#next', 
    	prev:   '#prev',
		pagerAnchorBuilder: function(idx, slide) { var i = idx +1; return '<a href="#">' + (i-1) + '</a> <em></em>'; },
		prevNextClick: function(isNext, idx, slide) { factDynamics(idx); },
		pagerClick: function(idx, slide) { factDynamics(idx); }
		});
 	$("#factSlideNav a:first").css("display", "none");
	
	
});

	// Shadowbox
	function addClickClose(){
		$('#sb-content').unbind('click').click(function(){ Shadowbox.close(); });
	}

	function flash(strFile, strId, intWidth, intHeight) {
		document.write("<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\" name=\"" + strId + "\" width=\"" + intWidth + "\" height=\"" + intHeight + "\" id=\"" + strId + "\">");
		document.write("<param name=\"movie\" value=\"/_assets/swf/" + strFile + "\" />");
		document.write("<param name=\"quality\" value=\"high\" />");
		document.write("<param name=\"wmode\" value=\"transparent\">");
		document.write("<param name=\"menu\" value=\"false\">");
		document.write("<embed src=\"/_assets/swf/" + strFile + "\" width=\"" + intWidth + "\" height=\"" + intHeight + "\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" menu=\"false\" name=\"" + strId + "\"></embed></object>");
	}