jQuery.noConflict();

function switch_image(id, new_image) {
	var src_default = jQuery("#default_image").text();
	var product_id = jQuery(".jFlowSelected").text();

	if(product_id) {
		if(new_image) {
			jQuery("#product_options a").removeClass("selected");
			jQuery("#option-"+id).addClass("selected");
			jQuery("#big_image_"+product_id).attr("src", new_image);
			// Update Email Friend Link
			jQuery("#email_friend").attr("href", "/email_friend.php?img="+new_image+"&prod_id="+product_id);
		}
		else {
			// default image
			jQuery("#product_options a").removeClass("selected");
			jQuery("#option-"+id).addClass("selected");
			jQuery("#big_image_"+product_id).attr("src", src_default);
			// Update Email Friend Link
			jQuery("#email_friend").attr("href", "/email_friend.php?img="+src_default+"&prod_id="+product_id);
		}
	}
}


function toggle_image(direction) {
	var cur_id = jQuery("#default_id").text();
	var product_id = jQuery(".jFlowSelected").text();

	if(cur_id) {
		// Reset Default image + options
		var cur_src = jQuery("#default_image").text();
		jQuery("#big_image_"+cur_id).attr("src", cur_src);
		jQuery("#product_options a").removeClass("selected");
		jQuery("#option-0").addClass("selected");
	}
	
	if(product_id && direction) {
		// Update Counter
		var count_start = (jQuery("#count_start").text())? jQuery("#count_start").text() : "01";
		var count_end = (jQuery("#count_end").text())? jQuery("#count_end").text() : "01";
		var counter = Math.abs(count_start);
		var counter_total = Math.abs(count_end);

		if(direction == "prev") {
			counter--;
		}
		if(direction == "next") {
			counter++;
		}
		if(counter < 10) {
			counter = String("0"+counter);
		}
		jQuery("#count_start").html(counter);

		// Update Arrows
		if(counter == 1) {
			jQuery("#link_left").css("display", "none");
			jQuery("#arrow_left_grey").css("display", "inline");
		}
		else {
			jQuery("#link_left").css("display", "inline");
			jQuery("#arrow_left_grey").css("display", "none");
		}

		if(counter == counter_total) {
			jQuery("#link_right").css("display", "none");
			jQuery("#arrow_right_grey").css("display", "inline");
		}
		else {
			jQuery("#link_right").css("display", "inline");
			jQuery("#arrow_right_grey").css("display", "none");
		}
		
		// Update Product Information
		jQuery.post("/get_box.php?products_id="+product_id, {product_id: product_id}, function(data){
			jQuery("#boxProduct").replaceWith(data);

			// Update Header Title
			if(jQuery("#product_name").text()) {
				jQuery("title").html("Brian Atwood : "+jQuery("#product_name").text());
			}

			// Update New Default ID + Product Src
			var product_src = jQuery("#big_image_"+product_id).attr("src");
			jQuery("#default_image").html(product_src);
			jQuery("#default_id").html(product_id);

			// Update Email Friend Link
			jQuery("#email_friend").attr("href", "/email_friend.php?img="+product_src+"&prod_id="+product_id);
		});
	}
}

function update_size() {
	if(jQuery(".state_box")) {
		var container_height = 0;
		var number_box = jQuery('.active').next('div.place').children('.state_row').children('.state_box').size();
		
		if(navigator.appName.toLowerCase() == "microsoft internet explorer") {
			container_height = number_box * 220;
		}
		else {
			container_height = number_box * 210;
		}

		if(container_height < 535) {
			container_height = 535;
		}

		jQuery("#stocklist").css("height", container_height+"px");
	}
}
