
function goLarge() {
		var handle = $("#fsiviewer");
		var margin = 50;
		var width = $(window).width()-2*margin;
		var height = $(window).height()-2*margin;
		//console.log($(window).height());

		//$(body).prepend(handle);


		handle.css("position","absolute");
		handle.width(width);
		handle.height(height);
		handle.css("top",margin);
		handle.css("left",margin);
		handle.css("z-index",3100);

		$("#fsiModalContainer a.modalCloseImg").css("left",width-30);

		$("object",$("#fsiModalContainer")).attr("width",width);
		$("object",$("#fsiModalContainer")).attr("height",height-10);

		$("embed",$("#fsiModalContainer")).attr("width",width);
		$("embed",$("#fsiModalContainer")).attr("height",height-10);


}

function enlargeFSI() {
	var handle = $("#fsiviewer");
	/*
	goLarge();
	return;
	/**/

	var viewerdata;

	if($.browser.msie){
		viewerdata = handle.html();
	}
	else{
		viewerdata = handle.clone();
	}

	//handle.modal({containerId: 'fsiModalContainer', onOpen: function(dialog) {
	$.modal(viewerdata,{containerId: 'fsiModalContainer', onOpen: function(dialog) {
		//console.log("TEST");

		var margin = 50;
		//var topmargin = $(document).srollTop() + 50; //should be used if I could find where to include dimensions.js?
		var width = $(window).width()-2*margin;
		var height = $(window).height()-2*margin;
		//console.log($(window).height());
		dialog.container.show();


		dialog.container.width(width);
		dialog.container.height(height);
		dialog.container.css("top",margin);
		dialog.container.css("left",margin);

		$("#fsiModalContainer a.modalCloseImg").css("left",width-30);

		$("object",$("#fsiModalContainer")).attr("width",width);
		$("object",$("#fsiModalContainer")).attr("height",height-10);

		$("embed",$("#fsiModalContainer")).attr("width",width);
		$("embed",$("#fsiModalContainer")).attr("height",height-10);
		/**/

		dialog.overlay.show();
		dialog.data.show();

	},
	onClosedd : function(dialog) {

		dialog.overlay.hide();
		dialog.container.hide();
		dialog.data.hide();
		$("#fsiviewer").html("");
		$("#fsiviewer").html('<object width="100%" height="100%" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,65,0" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"><param value="http://erez.mocsystems.com:8180/erez4/fsi4/fsi.swf?FPXBase=http://erez.mocsystems.com:8180/erez4%2Ferez%3Fsrc%3D&FPXSrc=Kontorkoncept%2FChoiseline%2FDenSorte%2Fchoiseline-00029.tif" name="movie"/><param value="transparent" name="wmode"/><embed width="100%" height="100%" wmode="transparent" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" src="http://erez.mocsystems.com:8180/erez4/fsi4/fsi.swf?&FPXBase=http://erez.mocsystems.com:8180/erez4%2Ferez%3Fsrc%3D&FPXSrc=Kontorkoncept%2FChoiseline%2FDenSorte%2Fchoiseline-00029.tif"/></object>');
		var width = 330;
		var height = 450;

		$.modal.close();

		$("object",$("#fsiModalContainer")).attr("width",width);
		$("object",$("#fsiModalContainer")).attr("height",height);

		$("embed",$("#fsiModalContainer")).attr("width",width);
		$("embed",$("#fsiModalContainer")).attr("height",height);
		/**/


		  /*dialog.overlay.fadeIn('slow', function () {
		    dialog.container.slideDown('slow', function () {
		      dialog.data.fadeIn('slow'); // See Other Notes below regarding
		                                     // data display property and
		                                     // iframe details
		    });
		  });
		  /**/
	}
	});


/**/
}

$.ajaxSetup({
  cache: false
});
var isSingleViewOpen = false;
function initSearchInputBox() {
	$("#search-result-container").hide();
	$("#search-display-single-product").hide();
	$("#sword").keyup(sendAjaxWait);
	//DEBUG
	/*
	$("#sword").val("bord");
	sendSubmitSearch();
	/**/

}
var TIMEOUT_ID;

function sendAjaxWait() {
	if(TIMEOUT_ID) {
		clearTimeout(TIMEOUT_ID);
	}
	TIMEOUT_ID = setTimeout(sendSubmitSearch,500);
}
function sendSubmitSearch() {
	if($("#sword").val().length>2) {
		val = $("#sword").val();
		$.get("?type=129&no_cache=1&ajax_cmd=search&sword="+val,{},updateUserSearchWindow);
	} else if($("#sword").val().length==0) {
		clearSearchResult();
	}
}
function updateUserSearchWindow(data) {
	$("#search-result").html(data);
	$("#search-result-container").slideDown(300);
	//$("#search-result-container").fadeIn(300);
	//$(".product-view-single").css("padding-top",220);
	$(".search-single-product").mouseover(searchProductMouseOver);
	$(".search-single-product").mouseout(searchProductMouseOut);
	$(".search-single-product").click(searchProductClick);
	$(".show-all-box").click(showAllResults);
		//DEPRECATED???
	if(isSingleViewOpen) {
			$("#product-search-spacer").show();
	}
}

function showAllResults(){
	//console.log("TEST");
	if($("#sword").val().length>2) {
		$.post("/produkter/?type=129&no_cache=1&ajax_cmd=search_all&sword="+$("#sword").val(),{}, showAllProducts);
	}
}

$(initSearchInputBox);
/**
* Called when someone click the close button.
*/
function closeSearchResultBox() {
	clearSearchResult();
}

function clearSearchResult() {
	$("#footerrow").css("padding-top",0);

	//@todo Here we should detect whether or not we have som content hidden or not....
	$(".product-view-single").css("padding-top",0);
	$("#search-result-container").hide(200);
}

function searchProductMouseOver() {
	//console.log($(this));
	$(this).removeClass('search-single-product-no');
	$(this).addClass('search-single-product-act');

}
function searchProductMouseOut() {
	//console.log($(this));
	$(this).removeClass('search-single-product-act');
	$(this).addClass('search-single-product-no');

}

function searchProductClick(element) {
    //var val = ($(element.target).parents(".search-single-product").attr("kk:product_uid"));
    var val = $(this).attr("kk:product_uid");
    $.post("/produkter/?type=129&ajax_cmd=display&product_uid="+val,{},showProduct);
    isSingleViewOpen = true;
}
function showProduct(data) {
//<div id="product-search-spacer" style="padding-top: 220px;">&nbsp;</div>' +


	$("#content-fp").html(data);
	$("#content-sub").html(data);

	$(".product-view-single").css("padding-top",230);
	$("#footerrow").css("margin-top",230);
	jQuery(init_slideimages);
}

function showAllProducts(data){
	$("#content-fp").html(data);
	$("#content-sub").html(data);
	closeSearchResultBox();
}