// JavaScript Document

$(document).ready(function(){

	//Country dropdown functionlity
	$("#country-selector").click(function() {
  	    var position = $("#country-selector").position();
   	    $("ul.countries").css("left", position.left - 158);
   	    $("ul.countries").css("top", position.top + 1);
		$("ul.countries").toggle();
	});
	
	var countriesLeft;
	
	$("ul.countries").bind("mouseleave", function() {countriesLeft = setTimeout(function(){
		$("ul.subcountries").hide();
		$("ul.countries").hide();}, 500);	
	});
	
	$("ul.countries").bind("mouseenter", function() {
		clearTimeout(countriesLeft);
	});
	
	$("ul.countries>li").hover(
		function(){$("ul", this).show()},
		function(){$("ul", this).hide()});
	
	$("ul.subcountries a").click(function() {
		$("#country-selector").text($(this).text());		
		$("ul.subcountries").hide();
		$("ul.countries").hide();
	});


	//clear serchbox on click
	$("#search-text").bind("focus", function() {
		if(this.value == "Search...")
			this.value = "";
	});
	
	$("#search-text").bind("blur", function() {
		if(this.value == "")
			this.value = "Search...";
	});
	
	//products functionality
	$(".product-selector").click(function() {
		if($(".product-selector-dropdown", this).css("display") == "block") {
			$(".product-selector-dropdown").hide();
		}
		else {
			$(".product-selector-dropdown").hide();
			$(".product-selector-dropdown", this).show().css("z-index", 200);
		}

	});
	
	
	// Light Box (Thick Box) functionality
	// Check if ThickBox classes are on the page, if they are, load script and CSS
	var thickbox_class = '.thickbox';
	if ($(thickbox_class)) {
		
		// Check if were're in a sub-directory
		// Hack to avoid hard-coded links in EVERY page
		var path_prefix = '';
		if ($(thickbox_class).attr('href').slice(0,3) == '../') {
			path_prefix = '../';
		}

		// Load CSS
		$('head').append(
			'<link type="text/css" rel="stylesheet" href="'+ path_prefix + 'css/thickbox.css" />'
		);
		// GET and load JavaScript
		$.getScript(path_prefix + 'scripts/thickbox-compressed.js', function(){});
		$.getScript(path_prefix + 'scripts/swfobject.js', function(){});

	}
});