// JavaScript Document

function showPopup(id, colour) {
	var url = "product_detail.php?ID=" + id + "&amp;colour=" + colour + "&amp;keepThis=true&amp;TB_iframe=true&amp;height=600&amp;width=800&amp;modal=true";
	tb_show(null, url);
	
}

function swapImg(newImg, bigImg, dimensions, id) {
		var sizeArr = dimensions.split(',');
		
		$('#Zoomer img').attr("src", newImg);
		$('#mainImage').attr("width", sizeArr[0]);
		$('#mainImage').attr("height", sizeArr[1]);
		
		$('.MagicZoomBigImageCont img').attr("src", bigImg);
		
		$('.MagicZoomBigImageCont').css("width", sizeArr[0] + "px !important");
		$('.MagicZoomBigImageCont').css("height", sizeArr[1] + "px !important");
		
		$('.zoomMe').attr("href", bigImg);
		
		$('a').removeClass('selected');
		$('#' + id).addClass('selected');
		
		return false;								 
}

function open_window(target,win_name,win_width,win_height) {
if (window.name == win_name) {
	window.location = target;
	return;
}
if (win_width > screen.width)   win_width = screen.width;
if (win_height > screen.height) win_height = screen.height;
var offset_left = (screen.width - win_width) / 2;
var offset_top  = (screen.height - win_height) / 2;
if (win_height > 100) {
win_height      = win_height - 100;
}
var win_cfg     = "status=1,scrollbars=1,resizable=1,width=" + win_width + ",height=" + win_height + ",left=" + offset_left + ",top=" + offset_top;
openwin         = window.open(target,win_name,win_cfg);
openwin.opener  = self; 
openwin.focus(win_name);
}

$(document).ready(function(){
	/*$('.product').click(function() {
		var product = $(this).attr('id');
		id = product.replace('product', '');
		var colour = $(this).attr('rel');
		location.hash = product;
		showPopup(id, colour);		
	});*/
	
	$('a.sendlink').click(function() {
		if ($('#sendlink').is(':hidden')) {
    		$('#sendlink').slideDown('slow');
    	} else {
			$('#sendlink').slideUp('slow');
		}
		return false;
	});
	
	$('.updateImage').click(function() {
		var img = $(this).attr('id');
		$('#mainImage').attr({src:img});
		$('a').removeClass('selected');
		$(this).addClass('selected');
		return false;
	});
	
	$('.hiddenPanel').hide();
	if ($.cookie('advanced')) {
		$('.advanced').show();
		$('#Advanced').addClass('dropped');
	}
	if ($.cookie('materials')) {
		$('.materials').show();
		$('#Materials').addClass('dropped');
	}
	if ($.cookie('colours')) {
		$('.colours').show();
		$('#Colours').addClass('dropped');
	}
	if ($.cookie('stars')) {
		$('.stars').show();
		$('#Stars').addClass('dropped');
	}
	
	$('.showme').click( function() {
		var panel = $(this).attr('id');
		var rel = $(this).attr('rel');
		panel = panel.toLowerCase();
		if ($(this).hasClass('dropped')) {
			$('.' + panel).slideUp('slow');
			$(this).removeClass('dropped');
			$.cookie(panel, null);
			if (rel == "showClose") $('img', this).attr({src:'/images/read_more.gif'});
		} else {
			$('.' + panel).slideDown('slow');
			$(this).addClass('dropped');
			$.cookie(panel, panel);
			if (rel == "showClose") $('img', this).attr({src:'/images/close.gif'});
		}
		
		return false;
	});
	
	$('.formSubmit').click( function() {
		var id = $(this).attr('title');
		$('#' + id).submit();
	});
	
	$('#keywords').click( function() {
		if ($('#keywords').val() == "Search Products...") $('#keywords').val('');
	});
	
	var hash = location.hash;
	if (!hash.indexOf('#product')) {
		id = hash.replace('#product', '');
		showPopup(id);
	}
	
	$('.swapCountry').click( function() {
		var id = $(this).attr('href');
		$('.swapCountry').removeClass('selected');
		$(this).addClass('selected');
		id = id.replace('#', '');
		$('#countries div').hide();
		if (id == 'all') {
			$('#countries div').slideDown();
		} else {
			$('#' + id).slideDown();
		}
	});
	
	$("a.zoomMe").fancybox();
	
	$("#viewModel").fancybox({
	    'padding'           : 10,
        'autoScale'     	: false,
        'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'width'				: 900,
		'height'			: 640
	});
	
});
