$(document).ready(function() {
	
	/*checking for ie6*/
	
	var string = navigator.userAgent;
	var version = string.substr(30,3);

	var url = $(location).attr('href');
	var urlArray = url.split("#");
	var sortCat = urlArray[1];
	
	if(sortCat != null) {
		
		if (version == '6.0') {
		
		$(".product").hide();
		$("."+sortCat).show();
		$(".product_sort").removeClass('selected');
		$("#"+sortCat).addClass('selected');
		
		} else {
		
		$('#ajax').hide();
		$('#loading').show();
		
		$('#ajax').load('/ajax?cat='+ sortCat +' #container', function() {
			$('#loading').fadeOut(100, function() {
				$('#ajax').fadeIn(300);
			});
		});
		$(".product_sort").removeClass('selected');
		$("#"+sortCat).addClass('selected');
		
		}
	}
	
	var url = '/wp-content/themes/insydeout/images';
	
	$("#rblack").simpletip({
		fixed: true,
		position: 'bottom',
		activeClass: 'tip-rblack',
		content: '<img class="tooltip_arrow" src="' + url + '/tooltip_arrow.gif" /><img class="swatch_detail" src="' + url + '/rblack.jpg" alt=\'Black - InsydeOut\' /><div class="tooltip_label">Black</div>'
	});
	$("#rbrown").simpletip({
		fixed: true,
		position: 'bottom',
		activeClass: 'tip-rbrown',
		content: '<img class="tooltip_arrow" src="' + url + '/tooltip_arrow.gif" /><img class="swatch_detail" src="' + url + '/rbrown.jpg" alt=\'Brown - InsydeOut\' /><div class="tooltip_label">Brown</div>'
	});
	$("#rgrey").simpletip({
		fixed: true,
		position: 'bottom',
		activeClass: 'tip-rgrey',
		content: '<img class="tooltip_arrow" src="' + url + '/tooltip_arrow.gif" /><img class="swatch_detail" src="' + url + '/rgrey.jpg" alt=\'Grey - InsydeOut\' /><div class="tooltip_label">Grey</div>'
	});
	
	$("#ccoal").simpletip({
		fixed: true,
		position: 'bottom',
		activeClass: 'tip-ccoal',
		content: '<img class="tooltip_arrow" src="' + url + '/tooltip_arrow.gif" /><img class="swatch_detail" src="' + url + '/ccoal.jpg" alt=\'Coal - InsydeOut\' /><div class="tooltip_label">Coal</div>'
	});
	$("#csea").simpletip({
		fixed: true,
		position: 'bottom',
		activeClass: 'tip-csea',
		content: '<img class="tooltip_arrow" src="' + url + '/tooltip_arrow.gif" /><img class="swatch_detail" src="' + url + '/csea.jpg" alt=\'Dupione Deep Sea - InsydeOut\' /><div class="tooltip_label">Dupione Deep Sea</div>'
	});
	$("#cwalnut").simpletip({
		fixed: true,
		position: 'bottom',
		activeClass: 'tip-cwalnut',
		content: '<img class="tooltip_arrow" src="' + url + '/tooltip_arrow.gif" /><img class="swatch_detail" src="' + url + '/cwalnut.jpg" alt=\'Dupione Walnut - InsydeOut\' /><div class="tooltip_label">Dupione Walnut</div>'
	});
	$("#cparadise").simpletip({
		fixed: true,
		position: 'bottom',
		activeClass: 'tip-cparadise',
		content: '<img class="tooltip_arrow" src="' + url + '/tooltip_arrow.gif" /><img class="swatch_detail" src="' + url + '/cparadise.jpg" alt=\'Dupione Paradise - InsydeOut\' /><div class="tooltip_label">Dupione Paradise</div>'
	});
	$("#ccrimson").simpletip({
		fixed: true,
		position: 'bottom',
		activeClass: 'tip-ccrimson',
		content: '<img class="tooltip_arrow" src="' + url + '/tooltip_arrow.gif" /><img class="swatch_detail" src="' + url + '/ccrimson.jpg" alt=\'Dupione Crimson - InsydeOut\' /><div class="tooltip_label">Dupione Crimson</div>'
	});
	$("#ctaupe").simpletip({
		fixed: true,
		position: 'bottom',
		activeClass: 'tip-ctaupe',
		content: '<img class="tooltip_arrow" src="' + url + '/tooltip_arrow.gif" /><img class="swatch_detail" src="' + url + '/ctaupe.jpg" alt=\'Linen Taupe - InsydeOut\' /><div class="tooltip_label">Linen Taupe</div>'
	});
	$("#cnatural").simpletip({
		fixed: true,
		position: 'bottom',
		activeClass: 'tip-cnatural',
		content: '<img class="tooltip_arrow" src="' + url + '/tooltip_arrow.gif" /><img class="swatch_detail" src="' + url + '/cnatural.jpg" alt=\'Linen Natural - InsydeOut\' /><div class="tooltip_label">Linen Natural</div>'
	});
	
	if (version == '6.0') {
	
	$(".product_sort").click(function() {
		$(".product_sort").removeClass('selected');
		var id = $(this).attr('id');
		$(".product:visible").fadeOut(300, function(){
			$("."+id).fadeIn(300);
		});
		$(this).addClass('selected');
	});
	
	$('#content_product').click(function(){
		$('#content_product').load('/ajax #container');
	});
	
	} else {
	
	$(".product_sort").click(function() {
		$(".product_sort").removeClass('selected');
		var id = $(this).attr('id');
		$('#ajax').fadeOut(300, function() {
			$('#loading').fadeIn(100, function() {
				$('#ajax').load('/ajax?cat='+ id +' #container', function() {
					$('#loading').fadeOut(100, function() {
						$('#ajax').fadeIn(300);
					});
				});
			});
		});
		$(this).addClass('selected');
	});
	
	}

});
