function changeList(list)
{
    $('#list').load('list.php?list=' + list.value);
}		

function handleClick(ctrl)
{
	if (ctrl.value == 'Sök produkt..')
		ctrl.value = '';
}

function changeSort(sort)
{
	var map = {};
	var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
		map[key] = value;
	});
	window.location = window.location.href.split('?')[0] + '?page=' + (map['page']=='0'?'0':'1') + '&order=' + sort.value;
}

 function swap(item, image) { 
     document.getElementById("main").src = image; 
	 $(".thumbnails > li").removeClass('lion');
	 $(".thumbnails > li").addClass('lioff');
	 $(item).parent().removeClass('lioff');
	 $(item).parent().addClass('lion');
 } 
 
function show_zoom(heading, subheading, imageurl) 
{
    $(".colour").text(subheading);
    $(".productheading").text(heading);
    
    $('#zoom_loading').show();
	$('#zoom_image').hide();
	$('#zoom').dialog('open');

	var img = new Image();  
  	$(img).load(function () 
	{
		$('#zoom_image').attr('src', imageurl);
      	$('#zoom_loading').hide();
		$('#zoom_image').show();	
    })
    .attr('src', imageurl);
}


function submitform()
{
    document.forms["search"].submit();
}

function register()
{
    document.forms["newsletter"].submit();
}


var statusmsg=""
function hidestatus(){
window.status=statusmsg
return true
}

function isValidEmailAddress(emailAddress) 
{
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	return pattern.test(emailAddress);
}

$.fn.clearForm = function() {
  return this.each(function() {
    var type = this.type, tag = this.tagName.toLowerCase();
    if (tag == 'form')
      return $(':input',this).clearForm();
    if (type == 'text' || type == 'password' || tag == 'textarea')
      this.value = '';
    else if (type == 'checkbox' || type == 'radio')
      this.checked = false;
    else if (tag == 'select')
      this.selectedIndex = -1;
  });
};

/* Url preview script (http://cssglobe.com)*/
 
this.screenshotPreview = function(){	
	/* CONFIG */
		
		xOffset = 10;
		yOffset = 30;
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	$("a.screenshot").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='screenshot'><img src='"+ this.rel +"' alt='url preview' />"+ c +"</p>");								 
		$("#screenshot")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		$("#screenshot").remove();
    });	
	$("a.screenshot").mousemove(function(e){
		$("#screenshot")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};


// starting the script on page load
$(document).ready(function(){
	screenshotPreview();
});


