// 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 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');
	}
	
	$('.showme').click( function() {
		var panel = $(this).attr('id');
		panel = panel.toLowerCase();
		if ($(this).hasClass('dropped')) {
			$('.' + panel).slideUp('slow');
			$(this).removeClass('dropped');
			$.cookie(panel, null);
		} else {
			$('.' + panel).slideDown('slow');
			$(this).addClass('dropped');
			$.cookie(panel, panel);
		}
		
		return false;
	});
	
	$('.formSubmit').click( function() {
		var id = $(this).attr('title');
		$('#' + id).submit();
	});
	
	$('#keywords').click( function() {
		if ($('#keywords').val() == "know your product") $('#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();
		}
	});
	
});