
this.goToManufacturerPage = function () {
	var manufacturerID = $(this).val();
	if (manufacturerID) {
		top.location = 'tillverkare-m-' + manufacturerID + '.html';
	};
};

this.goToDesignerPage = function () {
	var designerID = $(this).val();
	if (designerID) {
		top.location = 'designer-d-' + designerID + '.html';
	};
};

//execute when DOM is loaded
$(document).ready(function(){


	$("select[name='manufacturers_id']").bind('change', goToManufacturerPage);
	$("select[name='designers_id']").bind('change', goToDesignerPage);





	//$('input[type=checkbox]').checkbox();

	//hook change function to attribute selection on product page to update price
	$("select.jsProductAttributes").change(function () {
		//animate the price span to invisible
		$("span#holderProductPrice2").animate({opacity: 0.0}, "fast");
		//create variable str and add the products_id taken from input to the beginning
		var str = $("input#products_id").val() + ";";
		//create variable str and add the products_id taken from the url to the beginning
		//var str = window.location.search.substring(1) + ";";
		//loop through all selected options
		$("select.jsProductAttributes option:selected").each(function () {
			//add the options title into the str variable
			str += $(this).attr("title") + ";";
		}); //eof: loop through all selected options
		//load php file through ajax with str variable
		$.get("_ajax.php", {
			ajax: "pCheck",
			str: str
		}, function (data) {
			//fill the productPrice span with the data loaded with ajax
			$("span#productPrice").text(data);
			//animate the price span to visible
			$("span#holderProductPrice2").animate({opacity: 1.0}, "fast");
		}); //eof: load php file through ajax with str variable
	}); //eof: hook change function to attribute selection on product page to update price

	//zebra striped tables
	$(".stripeMe tr:odd").addClass("alt");
	//eof: zebra striped tables

	//section to remove normal submit button and insert image to call javascript
	//get input image src and set it in variable
	var AddToCartSrc = $("input#AddToCart").attr('src');
	//remove the regular input button, safety just for js deactivated
	$("input#AddToCart").remove();
	//add own image in the tabledata where input image was located
	$("td#JsAddToCart").append("<img src='" + AddToCartSrc + "' id='JsImgAddToCart' alt='Add To Cart'>");
	//eof: section to remove normal submit button and insert image to call javascript

	//hook function to click on the added image
	$("img#JsImgAddToCart").click(function() {
		//get the position of the shopping cart div into a variable
		var CartPosition = $("div#shopping_cartBox").position();
		//get the position, width, height and src from the product image into variables
		var ImagePosition = $("img#holderBigProductInfo2").position();
		var ImageWidth = $("img#holderBigProductInfo2").width();
		var ImageHeight = $("img#holderBigProductInfo2").height();
		var ImageSource = $("img#holderBigProductInfo2").attr('src');
		//append an image to the body with the same src as product image
		$("body").append("<img src='"+ImageSource+"' alt='Product Image' id='FloatingProductInfo'>");
		//set the css of the image to be placed and sized just like the original image
		$("img#FloatingProductInfo").css({
			position: "absolute",
			left: ImagePosition.left,
			top: ImagePosition.top,
			width: ImageWidth,
			height: ImageHeight
		}); //eof: set the css of the image to be placed and sized just like the original image
		//create an animation to shrink and move the image into the shopping cart div
		$("img#FloatingProductInfo").animate({
			left: CartPosition.left,
			top: CartPosition.top,
			width: "0",
			height: "0"
		}, "fast", "linear", function () {
			//remove the image
			$(this).remove();
			//set the products_id and produktantal inputs into variables
			var AjaxProductsId = $("input[name='products_id']").val();
			var AjaxProduktAntal = $("input[name='produktantal']").val();
			//create empty variable AjaxId
			var AjaxId = "";
			//loop through all select tags with a name that starts with id
			$("select[name^='id']").each(function () {
				//add the id and value of the current select tag to the AjaxId variable
				AjaxId = AjaxId + ', ' + $(this).attr('id') + '|' + $(this).val();
			}); //eof: loop through all select tags with a name that starts with id
			//use post to send the information to be added into the shopping cart
			$.post("_ajax.php", {
				ajax: "addToCart",
				products_id: AjaxProductsId,
				id: AjaxId,
				produktantal: AjaxProduktAntal
			}, function (data) {
				//use get to get the new shopping cart content from the ajax file
				$.get("_ajax.php", { ajax: "sCart" }, function(data) {
					//replace the shopping_cartBox with new shopping cart content
					$("#shopping_cartBox").replaceWith(data);

					tb_init('#shopping_cartBox a.thickbox, #shopping_cartBox area.thickbox, #shopping_cartBox input.thickbox');

				}); //eof: use get to get the new shopping cart content from the ajax file
			}); //eof: use post to send the information to be added into the shopping cart
		}); //eof: create an animation to shrink and move the image into the shopping cart div
	}); //eof: hook function to click on the added image

	//hook function to when delete checkboxes in shopping cart changes
	$("input.CartDeleteProduct").change(function () {
		//submit the shopping cart form to reload cart
		$("form#ShoppingCart").submit();
	}); //eof: hook function to when delete checkboxes in shopping cart changes

	//section for collapsable categories menu
	$("a.Collapsed.Parent, a.Expanded.Parent")
		//bind function showme to a tags
		.bind('showme', function () {
			//set data hidden to false and slidedown the children ul och the a tags parent li
			$(this).data("hidden", false).parent("li").children("ul").slideDown("slow");
			//get the link rel attribute into a variable
			var TheRel = $(this).attr("rel");
			//use get to call the php file used for ajax requests and send data with it and call function on success
			$.get("_ajax.php", {
				ajax: "reloadMain",
				pageBase: "index_nested",
				cPath: TheRel
			}, function (data) {
				//replace main div with a div filled with data returned from ajax request
				$("div#main").replaceWith("<div id='main'>" + data + "</div>");
			});
			//return false so no link click is followed
			return false;
		}) //eof: bind function showme to a tags
		//bind function hideme to a tags
		.bind('hideme', function () {
			//set data hidden to true and slideup the children ul och the a tags parent li
			$(this).data("hidden", true).parent("li").children("ul").slideUp("slow");
			//return false so no link click is followed
			return false;
		}) //eof: bind function hideme to a tags
		//bind function to click event on a tags
		.bind('click', function() {
			//remove class expanded and add collapsed to all a tags with class expanded
			$("a.Expanded").removeClass("Expanded").addClass("Collapsed");
			//remove the class collapsed and add the class expanded to the clicked a tag
			$(this).removeClass("Collapsed").addClass("Expanded");
			//trigger the showme or hideme bind depending och the data hidden
			$(this).trigger($(this).data("hidden") ? "showme" : "hideme");
			//return false so no link click is followed
			return false;
		}); //eof: bind function to click event on a tags
	//hide menu section that is the children ul och the a tags parent li
	$("a.Collapsed.Parent").data("hidden", true).parent("li").children("ul").hide();
	//eof: section for collapsable categories menu

}); //eof: execute when DOM is loaded