// Any link that starts with http must use target=blank
$(function() {
    $('a[href^=http]').not('a[href^=http://www.wouterswitgoed]').click( function() {
        window.open(this.href);
        return false;
    });
});

var Browser = {
  Version: function() {
	var version = 999; // we assume a sane browser
	if (navigator.appVersion.indexOf("MSIE") != -1)
	  // bah, IE again, lets downgrade version number
	  version = parseFloat(navigator.appVersion.split("MSIE")[1]);
	return version;
  }
}

//if (Browser.Version() < 8) {
//	//alert(Browser.Version());
//}



$(window).load(function(){
	
	// LEFT FILTERS
	$('select#brand').change(function()
	{ 
		var current = $(this);
		var id = current.attr("id");
		var value = current.val();
		//alert(id + " - " + value);	
		
		if(value.indexOf(".htm") >= 0)
			var new_url = value + $.query.remove("brand").remove("page").toString().replace("?","&");
		else
			var new_url = $.query.set("brand", value.replace("?brand=","")).remove("page").toString();	
			
//		if(value == "")
//			var new_url = $.query.remove("brand").remove("page").toString();
//		else
//			var new_url = $.query.set(id, value).remove("page").toString();			
		
		window.location.replace(new_url); 
		// simulates similar behavior as an HTTP redirect vs window.location.href = "http://www.turbocms.net"; simulates similar behavior as clicking on a link		
	});

	$('ul#filter_category a').click(function(e)
	{
		e.preventDefault();
		var current = $(this);
		var value = current.find('> span').html();
		var href = current.attr("href");
		//alert(value);

		// if link contains .htm then you need to use the link location (needed on homepage, when clicking a category you will go to nieuw witgoed page with that category selected
		if(href.indexOf(".htm") >= 0)
			var new_url = href + $.query.remove("category").remove("page").toString().replace("?","&");
		else
			var new_url = $.query.set("category", value).remove("page").toString();	
		
		//alert(new_url);
		window.location.replace(new_url); 
		//window.location.href(new_url); 
		// simulates similar behavior as an HTTP redirect vs window.location.href = "http://www.turbocms.net"; simulates similar behavior as clicking on a link		
	});

	
	// PRODUCTDETAIL
	// Fade in/out productfotos when the large image of the clicked thumb is not already visible
	$('ul.thumbs li a').click(function(e)
	{ 
		e.preventDefault();
		var current = $(this);
		var id = current.attr("href"); 
	
		if(!$(id).is(":visible"))
		{
			$('li.productphoto img:visible').fadeOut(170, function(){ 
				$(id).fadeIn(400);
			}); 	
		}
	});
	
	//
	$('a.back_to_overview').click(function(e){
		e.preventDefault();
		parent.history.back();
	});
	
});
