jQuery.noConflict();

function jcheckbox(image) {
	var id = jQuery(image).attr("id").replace("i_", "");
	var value = jQuery("input#"+id).val();
	var name = jQuery(image).attr('class').split(' ').slice(-1);
	jQuery("input.jcheckfield[name="+name+"]").attr("value", value);
	jQuery("img." + name).each(function(){
		var id = jQuery(this).attr("id").replace("i_", "");
		var value = jQuery("input#"+id).val();
		var name = jQuery(this).attr('class').split(' ').slice(-1);
		if ( value == jQuery("input.jcheckfield[name="+name+"]").attr("value")) {
			jQuery(this).attr("src", "/images/check_checked.jpg");
		} else {
			jQuery(this).attr("src", "/images/check_unchecked.jpg");
		}
	})
	jQuery("input#"+id).trigger('click');
};

jQuery(document).ready(function(){
	jQuery(".jcheckbox").each(function(){
		jQuery(this).css("display", "none");
		if( jQuery(this).is(":checked") ) {
			var id = jQuery(this).attr("id");
			var value = jQuery(this).val();
			var name = jQuery(this).attr( "name" );
			jQuery(this).attr("name", "js_"+ name);
			jQuery(this).after("<input class='jcheckfield' type='hidden' name='" + name + "' value='" + value + "' />");
			jQuery(this).before("<img id='i_"+id+"' onclick='jcheckbox(this);' class='jcheckbox "+name+"' src='/images/check_checked.jpg' />");
		} else {
			var id = jQuery(this).attr("id");
			var name = jQuery(this).attr( "name" );
			jQuery(this).attr("name", "js_"+ name);
			jQuery(this).before("<img id='i_"+id+"' onclick='jcheckbox(this);' class='jcheckbox "+name+"' src='/images/check_unchecked.jpg' />");
		}
	});
	
	jQuery("#McAfeeLink img").attr("oncontextmenu", "alert('Copying Prohibited by Law - McAfee Secure is a Trademark of McAfee, Inc.'); return false");
	
	jQuery("#quick_search input[name=keyword]").bind("focus", function() {
		this.value='';
	});
	
	jQuery("#helpbutton").bind("click", function() {
		window.open(this.href, '', 'width=600px,height=600px');
		return false;
	});
	
	jQuery("#chatbutton").bind("click", function() {
		this.newWindow = window.open(this.href, 'Chat', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=640,height=480');
		this.newWindow.focus();
		this.newWindow.opener = window;
		return false;
	});
	
	jQuery("#recent_open").show();
	
	jQuery("a[rel=external]").bind("click", function() {
		window.open(this.href);
		return false;
	});
	
	jQuery(".amount_div .close_btn").bind("click", function() {
		updateCart();
	});
	
	jQuery(".amount_div input[type=text]").bind("change", function() {
		updateCart();
	});
	
	jQuery(".amount_div input[type=button]").bind("click", function() {
		updateCart();
	});
	
	jQuery("#bijwerken").bind("click", function() {
		updateCart();
	});
	
	jQuery(".cart_amount_select").bind("change", function() {
		var itemKey = this.name.replace("aantal_s_", "");
		
		if (this.options[this.selectedIndex].value == '_-_') {
			document.getElementById('div_aantal_t_' + itemKey).style.display = 'block';
		} else {
			document.getElementById('aantal_t_' + itemKey).value = this.value;
			updateCart();
		}
	});
	
	jQuery("#info_btn").bind("mouseover", function() {
		jQuery('#ship_info').show();
	}).bind("mouseout", function() {
		jQuery("#ship_info").hide();
	});
});