// JavaScript Document

// JQuery ------------------------------------------------------------------------------
function GetCoords()
  {
    var scrollY;
    if (document.all)
    {

      if (!document.documentElement.scrollTop)
        scrollY = document.body.scrollTop;
      else
        scrollY = document.documentElement.scrollTop;
    }
    else
    {
      scrollY = window.pageYOffset;
    }
    return scrollY;
  }
  
$(document).ready(

function() 
{			
	// kundvagn
	
	$("#cart_trigger").click(function()
	{
		$.scrollTo(GetCoords(), { axis:'y' });
		$("#cart_info_wrapper").slideDown('slow');
		
		document.getElementById('cart_trigger').style.display='none';
		document.getElementById('cart_trigger_open').style.display='inline-block';
	});

	$("#cart_trigger_open").click(function()
	{
		$.scrollTo(GetCoords(), { axis:'y' });
		$("#cart_info_wrapper").slideUp('slow');
		
		document.getElementById('cart_trigger').style.display='inline-block';
		document.getElementById('cart_trigger_open').style.display='none';
		document.getElementById('cart_trigger').innerHTML = 'Visa varukorg';
	});
	
	$("#cart_trigger_open_empty").click(function()
	{
		$("#cart_info_wrapper").slideUp('slow');
		document.getElementById('cart_trigger_open_empty').style.display='none';
	});
	
	// Fullpostfunktioner
	
	if ($("#info").height() < 316 && $("#read_more").length!=0)
	{
		document.getElementById('read_more').style.display='none';
	}
	
	$("#read_more").click(function()
	{
			$.scrollTo(GetCoords(), { axis:'y' });
			$("#description").animate({height: $("#info").height()}, "slow");
			document.getElementById('close').style.display='block';
			document.getElementById('read_more').style.display='none';
	});
	
	$("#close").click(function()
	{
			$.scrollTo(GetCoords(), { axis:'y' });
			$("#description").animate({height: 316}, "slow");
			document.getElementById('read_more').style.display='block';
			document.getElementById('close').style.display='none';
	});
	
	$("#giftbox").click(function()
	{
		if(document.getElementById('giftmess').style.display=='none')
		{
			$("#giftmess").slideDown('slow');
		}
		else
		{
			$("#giftmess").slideUp('slow');
		}	
	});
	
	$("#reminder").click(function()
	{
		if(document.getElementById('reminderform').style.display=='none')
		{
			$("#reminderform").slideDown('slow');
		}
		else
		{
			$("#reminderform").slideUp('slow');
		}	
	});
	
	// Mediaplatta framsida
		
	$('#intro') 
	.after('<div id="nav">') 
	.cycle({ 
	fx:     'fade', 
	speed:  '1000', 
	timeout: 12000, 
	pager:  '#nav',
	next:   '#next',  
	cleartype:  1

	});
	
	$('#remote').toggle(function() {
			$('#inspiration').cycle('pause');
			$(this).attr({ src: "/img/play.jpg", title: "Spela bildspelet", alt: "Spela"});
				}, function() {

			$('#inspiration').cycle('resume', true);
			$(this).attr({src: "/img/pause.jpg", title: "Pausa bildspelet", alt: "Pausa"});
        });
	
	// Inspirationsplatta
		
	$('#inspiration') 
	.after('<div id="nav">') 
	.cycle({ 
	fx:     'fade', 
	speed:  '1000', 
	timeout: 12000, 
	pager:  '#nav',
	next:   '#next',  
	cleartype:  1

	});

}
);

// SEARCH BOX ------------------------------------------------------------------------------

$(function() {
	swapValues = [];
	$(".swap_value").each(function(i){
		swapValues[i] = $(this).val();
		$(this).focus(function(){
			if ($(this).val() == swapValues[i]) {
				$(this).val("");
			}
		}).blur(function(){
			if ($.trim($(this).val()) == "") {
				$(this).val(swapValues[i]);
			}
		});
	});
});

function externalLinks() {  
 if (!document.getElementsByTagName) return;  
 var anchors = document.getElementsByTagName("a");  
 for (var i=0; i<anchors.length; i++) {  
   var anchor = anchors[i];  
   if (anchor.getAttribute("href") &&  
       anchor.getAttribute("rel") == "external")  
     anchor.target = "_blank";  
 }  
}  
window.onload = externalLinks;

function toggle_visibility(part) 
{
	var e = document.getElementById(part);
	if(e.style.display == 'none'){
		e.style.display = 'inline';}
	else{
		e.style.display = 'none';}
}