$(document).ready( function() {
	
	$(".meta-box").hover( function() {
		$(".meta-box .content").slideToggle();
	}, function(){
		$(".meta-box .content").slideToggle();
	});
	
	
	// First word for kampanjer
	$('div.kampanj-main > div.title').each(function(){
		var me = $(this)
        , t = me.text().split(' ');
		me.html( '<font color="#f47321">'+t.shift()+'</font> '+t.join(' ') );
	});
	
	$(".produktbildspel").each(function() {
		var a = $(this).find(".bild");
		if(a.size() > 1) {
			var time = 5;
			timeoutProduktBildspel = setTimeout(nextProduktBildspel, time * 1000, this, time, currentProduktBildspel);
		}
		
		$(this).find(".arrowleft").click(function() {
			if(timeoutProduktBildspel != -1) {
				clearTimeout(timeoutProduktBildspel);
			}
			nextProduktBildspel($(".produktbildspel"), time, true);
		});
		$(this).find(".arrowright").click(function() {
			if(timeoutProduktBildspel != -1) {
				clearTimeout(timeoutProduktBildspel);
			}
			nextProduktBildspel($(".produktbildspel"), time, false);
		});
		
		$(this).find(".thumb").click(function() {
			if(timeoutProduktBildspel != -1) {
				clearTimeout(timeoutProduktBildspel);
			}
			var next = parseInt($(this).attr("index"));
			nextProduktBildspel($(".produktbildspel"), time, false, next);
		});
	});
	
	$("#bildspel").each(function() {
		$(this).find(".bildplats").each(function() {
			var time = parseFloat($(this).attr("time"));
			var fadeTime = parseFloat($(this).attr("fadeTime"));
			var delay = parseFloat($(this).attr("delay"));
			var current = 0;
			
			setTimeout(nextBildspel, (time + delay) * 1000, this, time, fadeTime, delay, current);
		});
	});
	
	$(".bildplats").click(function() {
		document.location.href = $(this).attr("link");
	});
	
	$(".bildplats").each(function() {
		if($(this).find(".bildplatstitle").html().indexOf("<br") != -1)
			$(this).find(".bildplatsfootershadow").height(165);
	});
	

});

var timeoutProduktBildspel = -1;
var currentProduktBildspel = 0;

function nextProduktBildspel(that, time, prev, cur) {
	var a = $(that).find(".bild");
	a.eq(currentProduktBildspel).fadeTo("slow", 0);
	if(cur >= 0) {
		currentProduktBildspel = cur;
	}
	else {
		if(prev)
			currentProduktBildspel--;
		else
			currentProduktBildspel++;
	}
	if(currentProduktBildspel < 0)
		currentProduktBildspel = a.size() - 1;
	if(currentProduktBildspel >= a.size())
		currentProduktBildspel = 0;
	a.eq(currentProduktBildspel).fadeTo("slow", 1);
	
	timeoutProduktBildspel = setTimeout(nextProduktBildspel, time * 1000, that, time);
}

function nextBildspel(that, time, fadeTime, delay, current) {
	var a = $(that).find(".bild");
	a.eq(current).fadeTo("slow", 0);
	current++;
	if(current >= a.size())
		current = 0;
	a.eq(current).fadeTo("slow", 1);
	
	setTimeout(nextBildspel, time * 1000, that, time, fadeTime, delay, current);
}


edit = 'false';
	
	function setedittext(text) {
		var a = document.getElementById('editiframetext');
		if(a)
		{
			a.style.visibility = text != '' ? 'visible' : 'hidden';
			a.innerHTML = text;
		}
	}
	
	function showedit(editurl) {
			
			if (edit == 'true'){
			//	alert('test');
		  edit = 'false';
     	frames['edit1'].location.href='includes/loading.html';
		  document.getElementById('editframe').style.display='none';
		  document.getElementById('editframe').style.visibility='hidden';
		  document.getElementById('centerframe').style.display='none';
		  document.getElementById('centerframe').style.visibility='hidden';
		  max = 'false';
    	document.getElementById('editiframe').style.width='800';
   		document.getElementById('editiframe').style.height='400';
    	document.getElementById('editiframe').style.margin='50px auto';
    	document.getElementById('editiframe').style.border='1px solid white';
    	document.getElementById('edit1').style.height='400';
    	
    	

		  }
		  else {
		  edit = 'true';
		  //document.getElementById('edit1').src=editurl;	
		 	frames['edit1'].location.href=editurl;
		  document.getElementById('editframe').style.display='inline';
		  document.getElementById('editframe').style.visibility='visible';
		  document.getElementById('centerframe').style.display='inline';
		  document.getElementById('centerframe').style.visibility='visible';

			}
    
    }
	
	
	
	function iprint(ptarget) 
{ 
ptarget.focus(); 
ptarget.print(); 
} 
function show(aName) { 
			
				var divElement = document.getElementById(aName); 
				divElement.style.display = ''; divElement.style.visibility = 'visible'; 
				
				 }
function hide(aName) { 
			
				var divElement = document.getElementById(aName); 
				divElement.style.display = 'none';divElement.style.visibility = 'hidden'; 
				 }
				 
				 
function hidestatus(){
	window.status=''
	return true
	}
	
	if (document.layers)
	document.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT)
	
	document.onmouseover=hidestatus
	document.onmouseout=hidestatus
	
	function none() { 
	 }
	 
	 function flip(aName) { 
			
	var divElement = document.getElementById(aName); 
	if (divElement == null) { divElement = eval(aName); } 
	if (divElement.style.display == 'none') { divElement.style.display = ''; divElement.style.visibility = 'visible'; 
	} else {
	 divElement.style.display = 'none';
	 divElement.style.visibility = 'hidden'; } 
	 }


