var params = {};
params.wmode = "transparent";

var flashvars = {};
flashvars.transitionSpeed = 0.8; // speed for transition in seconds
flashvars.transitionDelay = 4 // delay of transition in seconds
flashvars.rotationDirection = "clockwise"; // clockwise, counter, random
flashvars.transitionEase = "Expo.easeOut" // ( easeOut, easeIn, easeInOut ) : Back, Expo, Strong, Quart, Elastic, Bounce, Regular
flashvars.brightnessTween = "false"; // true or false
flashvars.base = "http://www.eloenergi.se/"; // the base url
flashvars.links = "forsakring,garanti,leverans,rotavdrag,lana-slap,rantefritt"; // permalinks in clockwise order
flashvars.clickableLinks = "true"; // true or false
flashvars.hoverDelay = 0.08; // delay before Link-RollOver get fired

swfobject.embedSWF("http://www.eloenergi.se/admin/templates/eloe_eloenergi/halfabee_eloenergi.swf", "flash-btn", "268px", "268px", "10.1.0", "#ffffff", flashvars, params);

$(document).ready(function(){
	
	var count = 1;
	$(".extra-field-ankar-name.first").show();
	$("#extra-nav ul li a").each(function() {							  
		if(count == 1) { $(this).addClass("active"); }
		$(this).click(function() {
			var id = "#"+$(this).parent().attr("class");
			$("#extra-nav ul li a").removeClass("active");
			$(this).addClass("active");
			if(!$(id).is(":visible")) {	
				$(".extra-field-ankar-name").slideUp(300);
				$(id).slideDown(300);
			}
			return false;
		});
		count++;
	});
	
	$(".extra-field").each(function() {
		if($(this).find("img").length) {
		} else {
			$(this).css("margin", "0px 40px");
			
		}
	});
	
	if($("#section-bottom")) {
		$("#section").height(($("#section").height() + $("#section-bottom").height()));
	}
	
	$(".box-contact").hover(function() {
		$(this).find(".box-contact-text").show();
	}, function() {
		$(this).find(".box-contact-text").hide();
	});
	
	
	// SELECTLIST
	var selectSpeed = 160;
	if($(".select-list")) {

		var html = ($(".select-list select option[selected=selected]").length != 0) ? $(".select-list select option[selected=selected]").html() : $(".select-list select option").html();
		var value = ($(".select-list select option[selected=selected]").length != 0) ? $(".select-list select option[selected=selected]").val() : $(".select-list select option").val();
		$(".select-list").append('<div id="'+$(".select-list select").attr("name")+'" class="select-list-container"><div class="select-item-top">'+html+'</div>' + 
		'<div class="select-list-content"></div>'+
		'<input type="hidden" name="'+$(".select-list select").attr("name")+'" value="'+value+'" />'+
		'</div>');
		
		$(".select-list select option").each(function() {
			$(".select-list-content").append('<div id="'+$(this).val()+'" class="select-item">'+$(this).html()+'</div>');
		});
		$(".select-list select").remove();
		var selectContent = $(".select-list-content");
		$(".select-list-container .select-item-top").click(function() {
			if($(".select-list-content").is(":visible")) {
				selectContent.slideUp(selectSpeed);
				
			} else {
				selectContent.slideDown(selectSpeed);
				$(".select-item").click(function() {
					$(".select-list-container input").val($(this).attr("id"));
					$(".select-item-top").html($(this).html());
					selectContent.slideUp(selectSpeed);
				});
				
			}
		});
	}
	
	$(window).scroll(function() {
		if($(this).scrollTop() > 129) {
			$("#subnav").addClass("stickIT");
			//$("#subnav").css( {top: ($(this).scrollTop() - 180)+"px"}, 60);
		} else  {
			$("#subnav").removeClass("stickIT");
			//$("#subnav").css( {top: "-40px"}, 60);
		}
	});
	
	$("#menu-animate").css("width",$("#menu-animate ul").width());
	
	var animates = "slide";
	var speed = 400;
	var timer = 8000;
	var ClickStopInterval = true;
	var totWidth = 0;
	var marginRight = 5;
	var positions = new Array();
	$('#animate-content .animate').each(function(i){
		positions[i]= totWidth;
		totWidth += $(this).width() + marginRight;
		if(!$(this).width()) {
			alert("Please, fill in width & height for all your images!");
			return false;
		}
	});
	
	$('#animate-content').width(totWidth);
	$('#menu-animate ul li a').click(function(e,keepScroll) {
		$('li.menuItem').removeClass('act').addClass('inact');
		$(this).parent().addClass('act');
		var pos = $(this).parent().prevAll('.menuItem').length;
		if(animates == "fade") {
			$(".animate").fadeOut(speed, function() {
				$('#animate-content').stop().animate({marginLeft:-positions[pos]+'px'},0);
				$(".animate").fadeIn(speed);
			});
		} else if(animates == "slide") {
			$('#animate-content').stop().animate({marginLeft:-positions[pos]+'px'}, speed);
		}
		
		e.preventDefault();
		// Stopping the auto-advance if an icon has been clicked:
		if(!keepScroll && ClickStopInterval == true) { 
			clearInterval(itvl);
		
		}
	});
	
	$('#menu-animate ul li.menuItem:first').addClass('act').siblings().addClass('inact');
	/* Enabling auto-advance. */
	var current=1;
	function autoAdvance() {
		if(current==-1) return false;
		$('#menu-animate ul li a').eq(current%$('#menu-animate ul li a').length).trigger('click',[true]);
		current++;
	}
	
	var itvl = setInterval(function(){autoAdvance()}, timer);
	


	$(".hab-fancy").click(function() {
		$("body").append('<div id="hab-fancy-loading"></div><div id="hab-fancy-bg"></div>');
		
		$.ajax({
			method: "get", url: "http://www.eloenergi.se/index.php", data: "ajaxtget=1",
			beforeSend: function(){ },
			complete: function(){ },
			success: function(html) {
				
				$("#hab-fancy-loading").remove();
				$("body").append('<div id="hab-fancy-container">'+
								 '<a id="hab-fancy-close" href="#">St&auml;ng</a>'+
								 '<div id="hab-fancy-top"></div><div id="hab-fancy-bottom"></div>'+
								 html+
								 '</div>');
				
				// CLOSE
				$("#hab-fancy-close, #hab-fancy-bg").click(function() {
					$("#hab-fancy-bg, #hab-fancy-container").remove();
				});
				
			}
		});
		return false;
	});
	
	
	
	
});
