
$(document).ready(function () {
	
	var quoteArray = new Array();
	quoteArray[0] = '&quot;Sprayen har räddat livet på mig minst en gång&quot;<div class=\"quote-small\"><br>- Ann-marie, Taxiförare, Stockholm -<\/div>';
	quoteArray[1] = '&quot;Två killar hotade mig att jag skulle ge dom min mobil, dom gick direkt när jag tog fram sprayen&quot;<div class=\"quote-small\"><br>- Simon, Malmö -<\/div>';
	quoteArray[2] = '&quot;På väg hem mitt i natten försökte någon dra iväg mig, jag använde sprayen och kom undan!&quot;<div class=\"quote-small\"><br>- Malin, Linköping -<\/div>';
	quoteArray[3] = '&quot;Tack! Era sprayer fungerar verkligen, jag vet för jag har tyvärr behövt använda den redan.&quot;<div class=\"quote-small\"><br>- Josefine, Halmstad -<\/div>';
	quoteArray[4] = '&quot;Jag blev överfallen av ett gäng, men kom undan tack vare larmet!&quot;<div class=\"quote-small\"><br>- Klas, Göteborg -<\/div>';

	$('#quote').cycle({ timeout: 5000, cleartype: 1, speed: 300 });
	$('#displayMiddle').cycle({ timeout: 4000, cleartype: 1, speed: 300, cleartypeNoBg: true });
	
	$('#space img').hover(function() {
		$('#displayMiddle').cycle('pause');
		var self = $(this);
		
		$("div[id*='layer_media']").each(function() {
			$(this).removeAttr("style");
			$(this).hide();
		});
		
		var id = self.attr('id');
		$('#layer_'+id).show();
	},
	function() {
		/*$('#displayMiddle').cycle({ timeout: 3000, cleartype: 1, speed: 300, cleartypeNoBg: true });*/
		setTimeout("$('#displayMiddle').cycle('resume')", 3000);
	}
	
	);
	
	$(".video").click(function() {
		$.fancybox({			
				'padding'		: 0,
				'autoScale'		: false,
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'none',
				'easingIn'      : 'easeOutBack',
				'easingOut'     : 'easeInBack',
				'title'			: '',
				'titlePosition' : 'outside',
				'overlayOpacity': '0.5',
				'overlayColor'	: '#000',
				'titleFormat'	: '',
				'width'			: 680,
				'height'		: 495,
				'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
				'type'			: 'swf',
				'swf'			: {
					'wmode'				: 'transparent',
					'allowfullscreen'	: 'true'
				}
			});
	
		return false;
	});
	
							
	$("#parentDiv").css("height", $(document).height()); 
	
	$('#waitIndicatorDiv').click(function () {
		$("#parentDiv").hide();
		$("#waitIndicatorDiv").hide();
	});
	
	$('#closeDiv').click(function () {
		$("#parentDiv").hide();
		$("#tellAfriendDiv").hide();
		$("#waitIndicatorDiv").hide();
	});
	
	$(window).bind("resize", function(){  
		$("#parentDiv").css("height", $(window).height());  
	}); 

	var height = $('#cartbig').height();
	var height2 = $('#cartsmall').height();
	$('#cartbig').hide().css({ height: 0 });

	$('.cartToggle').click(function () {
		if ($('#cartbig').is(':visible')) {
			$('#cartbig').animate({ height: 0 }, { duration: 400, complete: function () {
				$('#cartbig').hide();
				$('#cartsmall').show().animate({ height: height2 }, { duration: 300 });
			} });
		} else {
			$('#cartsmall').animate({ height: 0 }, { duration: 200, complete: function () {
				$('#cartsmall').hide();
				$('#cartbig').show().animate({ height: height }, { duration: 400 });
			} });			
		}
		
		return false;
	});
		
	$('.mainmenu').click(function () {
		var self = $(this);
		
		var currClass = self.closest('li').attr('class').split(' ').slice(-1);
		
		if(currClass == 'catClosed')
		{
			self.closest('li').removeClass('catClosed');
			self.closest('li').addClass('catOpen');
			//self.closest('li').css('background-image', 'url(/static/images/arrow_right.png)');
			//self.data('expanded', false);
		}
		else if(currClass == 'catOpen')
		{
			self.closest('li').removeClass('catOpen');
			self.closest('li').addClass('catClosed');
			//self.closest('li').css('background-image', 'url(/static/images/arrow_down.png)');
			//self.data('expanded', true);
		}
	});
	
    $(".icon").hover(
      function () {
        $(this).css({backgroundPosition: '0px -25px'}); 
      }, 
      function () {
        $(this).css({backgroundPosition: '0px 0px'});
	  }
    );
	
	$("#iconFavorite").click(function(){
		url=location.href;
		title=document.title;
		if (window.sidebar) { // Mozilla Firefox Bookmark
			window.sidebar.addPanel(title, url,"");
		}
		else if(navigator.userAgent.toLowerCase().indexOf('chrome') > -1){
			alert('Klicka OK sen tryck CTRL+D'); }
		else if( window.external ) { // IE Favorite
			window.external.AddFavorite( url, title); }
		else  { // Opera Hotlist
			alert('Klicka OK sen tryck CTRL+D'); }
	});
	
	
	$(".cmtTrigger a").click(function(){
		var self = $(this);
		if(!self.data('expanded'))
		{
			self.data('startheight', self.closest('.commentRowWrap').height());
			var height = self.find('img').attr("alt");
			if(height < self.data('startheight')) height = self.data('startheight');
			if(!height){ height = 150; }
			self.closest('.commentRowWrap').animate( { height:height }, { duration:300 } );
			self.closest('.commentRowWrap').find('.textShort').hide(100);
			self.closest('.commentRowWrap').find('.textAll').show(300);
			//self.closest('.commentRowWrap').textAll.show();
			self.find('img').attr({
				src: 'static/images/arrow_down.png'
			});
			self.data('expanded', true);
		}
		else
		{
			self.closest('.commentRowWrap').animate( { height:self.data('startheight') }, { duration:300 } );
			self.closest('.commentRowWrap').find('.textAll').hide(100);
			self.closest('.commentRowWrap').find('.textShort').show(300);
			self.find('img').attr({
				src: 'static/images/arrow_right.png'
			});
			self.data('expanded', false);
		}
		return false;
	});
	
	/*
	var $div = $('.commentRowWrap');
	$('.commentArrow').click(function () {
		if ($div.is(':visible')) {
			$div.animate({ height: 113 }, { duration: 500 });
		} else {
			$div.show().animate({ height : 300 }, { duration: 600 });
		}
		
		return false;
	});
	*/

});


var win= null;
function openPopup(url,w,h)
{
	var winl = (screen.width-w)/2;
	var wint = (screen.height-h)/2;
	var settings ='height='+h+',';
	settings +='width='+w+',';
	settings +='top='+wint+',';
	settings +='left='+winl+',';
	settings +='scrollbars=yes,';
	settings +='resizable=no';
	win=window.open(url,'window',settings);
	
	if(parseInt(navigator.appVersion) >= 4) {win.window.focus();}
}

function Toggle(item)
{
   obj=document.getElementById(item);
   visible=(obj.style.display!="none");
   key=document.getElementById("x" + item);
   
   if(visible)
   {
     obj.style.display="none";
   }
   else
   {
      obj.style.display="block";
   }
   
   /*if(Get_Cookie('menu_id') == item)
   {
   	Set_Cookie('menu_id', '', '', '/', '', '');
   }
   else
   {   
   	Set_Cookie('menu_id', item, '', '/', '', '');
   }*/
}

function showWait(timer)
{
	if(timer)
	{
		// Show for limited time (timer). fadeTo acts as fader and delay.
		$("#waitIndicatorDiv").fadeTo((timer/2), 0.9).fadeTo((timer/2), 0.9).fadeOut('slow');
		$("#parentDiv").fadeTo((timer/2), 0.5).fadeTo((timer/2), 0.5).fadeOut('slow');
	}
	else
	{
		// Show untill page reloads		
		$("#waitIndicatorDiv").fadeTo(1, 0.9).show();
		$("#parentDiv").fadeTo(1, 0.5).show();
	}
}

function showTellAfriend()
{
	// Show untill closed	
	$("#tellAfriendDiv").fadeTo(1, 0.9).show();
	$("#parentDiv").fadeTo(1, 0.5).show();
}

// Preload images
(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)

