var d = document;
$(document).ready(function(){
	
	$.fn.tagName = function(){return this.get(0).tagName.toLowerCase();}
	function get_val(s){var a=window.location.search.substring(1).split('&');for(i=0;i<a.length;++i){b = a[i].split('=');if(b[0]==s){return b[1];}}return 0;}

	$('#left_menu.left_menu .sub_menu').parent().hide();

	$('.left_menu li a').click(function(){
		if($(this).parent().next().has('ul').length > 0){
			$(this).parent().next().toggle();
			var ajax_data = 'id='+ $(this).attr('rel');
			$.post('/ajax/products.php', ajax_data, function(data){
				$('#products_content').html(data);
			});
			return false;
		}else{
			return true;
		}
	}); // .left_menu li a
	
	$("a.cbox, a[rel=cbox]").colorbox({
		maxWidth : "98%"
		, maxHeight: "98%"
	});

	var page = document.location.pathname.substring(1);
	$('.left_menu a[href='+ page +']').addClass('active').parents().each(function(){
		if($(this).attr('id') == 'left_menu'){ return false; } else { $(this).show(); }
	}); // .left_menu a[href='+ page +']

	$('.left_menu a.active').parent().next().show();

	$('#important a.hide_important_body').click(function(){
		if( $(this).next().css('display') == 'none') {
			$(this).html('-');
			$(this).parent().css('border-width', '2px');
		} else {
			$(this).html('+');
			$(this).parent().css('border-width', '0');
		}

		$(this).next().slideToggle();
		return false;
	}); // #important a.hide_important_body

	
	$('a.compare').click(function(){
		var id = $(this).attr('rel');
		var t = $(this)
		
		if(parseInt(id) > 0) {
			$.ajax({
				url : '/ajax/compare.php',
				data : 'id='+ id +'',
				method : 'get',
				success: function(data) {
					if(data.length > 10) {
						alert(data);
					} else {
						t.html(data);
					}
				}
			});
		}
		
		return false;		
	}); // a.compare
	
});
