jQuery.sliderGallery= (function(current,maxdiswidth) {
	
	var $fp_gallery			= $('#fp_gallery'); //the main wrapper of the gallery
	var $fp_overlay			= $('#fp_overlay'); //the overlay when the large image is displayed
	var $fp_loading			= $('#fp_loading'); //image loading status
	var $fp_next			= $('#fp_next');//the next and previous buttons
	var $fp_prev			= $('#fp_prev');
	var $fp_close			= $('#fp_close');//the close button
	var $fp_thumbContainer 	= $('#fp_thumbContainer');//the main container for the thumbs structure
	var $fp_scrollWrapper	= $('#fp_scrollWrapper');//wrapper of jquery ui slider
	var $fp_contentWrapper 	= $('#fp_contentWrapper');
	var nmb_images			= 0; //total number of images
	var gallery_idx			= -1; //which gallery is clicked (index)
	var $fp_thumbScroller	= $('#fp_thumbScroller');//scroller wrapper
	var $slider				= $('#slider');//jquery ui slider
	var $fp_galleries		= $('#fp_galleryList > li');//the galleries
	//var current				= 0;//current image being viewed   //pass from details.php
	
	var fp_thumbContainerHeight=$fp_thumbScroller.height();
	var fp_thumbContainerWidth=$fp_thumbScroller.width();
	var fp_thumbContainerCenter=fp_thumbContainerWidth/2;
	
	//alert (fp_thumbContainerHeight);//debug
	//alert (fp_thumbContainerWidth);//debug
	//alert (fp_thumbContainerCenter);//debug
	
	//some control flags:
	//prevent fast clicks on next and previous
	var photo_nav			= true;
	
	
	//User clicks on a gallery;
	/*
	$fp_galleries.bind('click',function(e){
		$fp_galleries.removeClass('current');
		var $gallery 		= $(this);
		$gallery.addClass('current');
		//alert ($gallery);//debug
		var gallery_index 	= $gallery.index();
		if(gallery_idx == gallery_index) return;
		gallery_idx			= gallery_index;
		//close the gallery and slider if opened
		if($fp_thumbContainer.data('opened')==true){
			$fp_scrollWrapper.fadeOut();
			$fp_thumbContainer.stop().animate({'height':'0px'},200,function(){
				openGallery($gallery);
			});
		} else {
			openGallery($gallery);
		}
		//alert(gallery_idx);//debug
		
	});
	*/
	
	
	//open a gallery directly
	//
	var $gallery=$fp_galleries;
	var gallery_idx = $gallery.index();
	openGallery($gallery);  
	//
	
	
	//opens a gallery after cliking on a gallery
	function openGallery($gallery){
		//alert (gallery_idx);//debug

		nmb_images	= $fp_contentWrapper.children('div').length; //total number of items
		
		//alert($fp_contentWrapper);//debug
		//alert('current: '+current);//debug
		//alert('nmb_images :'+nmb_images);//debug
		
		
		//calculate width, padding left and padding right for content wrapper $fp_contentWrapper
		var w_width 	= 0; //total width of $fp_contentWrapper (all element div)
		var w_margin 	= 0; //total margin of $fp_contentWrapper (all element div)
		var widthAdjust = Math.ceil(nmb_images/2); //set overall width higher when not all shown
		var padding_l	= 0;
		var padding_r	= 0;
		var center		= fp_thumbContainerCenter;
		var one_divs_w  = 0;
		
		
		//Note:
		//the padding left is the center minus half of the width of the first content div
		//the padding right is the center minus half of the width of the last content div
		$fp_contentWrapper.children('div').each(function(i){ //loop throught each item div
			var $div = $(this);
			//alert ($div.html());//debug
			
			var div_marginLR = parseInt($div.css('margin-left')) + parseInt($div.css('margin-right')); 
			var div_width	= parseInt($div.css('width'));

			w_margin += div_marginLR; //total margin = sum of all item margin
			w_width	+= div_width; //total width = sum of all item width
			//alert ('div_width '+i+': '+ div_width); //debug
			//alert ('div_marginLR '+i+': '+ div_marginLR); //debug
			
			//alert ($div.attr('id'));//debug
			if(i==0) //if first one, calculates the padding left for contentWrapper
				padding_l = center - (div_width/2);
			else if(i==(nmb_images-1)){ //if last one, lets calculate the padding right for contentWrapper
				padding_r = center - (div_width/2);
				one_divs_w= div_width;
			}	
		}).end().css({ //set style of $fp_contentWrapper
			'padding-left' 		: padding_l + 'px',
			'padding-right' 	: padding_r + 'px',
			'width'				: w_width  +  w_margin + widthAdjust+ 200 +'px'  // final width for $fp_contentWrapper   increase width solve item not show but don't know why yet!!!
		});
		
		var sliderTravel=$slider.width();	
		//var sliderMax=(w_width+w_margin+padding_l+padding_r+widthAdjust)-sliderTravel;   //calculate max slider travels
		var sliderMax=$fp_contentWrapper.width();
		//var sliderMax= w_width ;
		
		
		
		//debug
		var sliderdebug = 'width: '+ (w_width  + w_margin + widthAdjust) + 'px' + "&nbsp; &nbsp; &nbsp;"
		+ 'w_width: '+ w_width + 'px' + "&nbsp; &nbsp; &nbsp;"
		+ 'w_margin: '+ w_margin + 'px' + "<br>"
		+ 'padding_l: '+ padding_l + 'px' + "&nbsp; &nbsp; &nbsp;"
		+ 'padding_r: '+ padding_r + 'px' + "<br>"
		+ 'one_divs_w: ' + one_divs_w + 'px' + "&nbsp; &nbsp; &nbsp;"
		+ 'center :'+ center + 'px' + "&nbsp; &nbsp; &nbsp;"
		+ 'widthAdjust :'+ widthAdjust + 'px' + "<br>"
		+ 'current :'+current + "<br>"
		+ 'sliderMax: '+ sliderMax + "<br>";
		
	
		$('.sliderdebug').html(sliderdebug);
		//debug
		
		
		
		//build and innitialize the slider
		$slider.slider('destroy').slider({
			orientation	: 'horizontal',
			animate		: true, 
			max 		: sliderMax,
			min			: 0,
			value		: 0,
			slide		: function(event, ui) {
							$fp_thumbScroller.scrollLeft(ui.value);  //specify element to be scrolled
						  },
			stop: function(event, ui) {
							checkClosest(); //get the closest item to the center to stays centered once scroll stops
						  }
		});
		
		
		$fp_thumbScroller.scrollLeft(w_width); //scroll to far right;
		//$fp_thumbScroller.stop().animate({'scrollLeft':sliderMax+'px'},1000,'jswing'); //scroll to far right;
		
		
		$.doTimeout(0, function(){ 
			//easing: swing, jswing, easeOutBounce, easeOutSine, easeOutCubic, easeOutQuad easeInOutExpo
			$fp_thumbScroller.stop().animate({scrollLeft:0},1000,'jswing'); //scroll to far left;
			centerimagebyIndex(current,1000,600); //center slider to current item
		});

		
		$.doTimeout(1500, function(){ 
			highlightItem(current,200);
		});


		//item clicked
		$fp_contentWrapper.find('.content').bind('click',function(e){
			e.preventDefault(); //prevent default click target
			var $current 	= $(this);
			current			= $current.index(); //index of clicked item
			
			//alert ($current.html());//debug
			centerImage($current,100,600);
			showitemDetails(current,nmb_images,maxdiswidth);  // function in details.php
			highlightItem(current,100);
		});					
		
		
		

		//previous button clicked
		$('#previousOne').click(function(e){ // previous item
			e.preventDefault(); // ignore default href action
			
			if (current > 0) {
				--current;
				slideThumb(0);//move left
			} else {
				current=nmb_images-1; //move to last one
				//$fp_thumbScroller.stop().animate({'scrollLeft':sliderMax+'px'},1000,'jswing');  //scroll to far right
				centerimagebyIndex(current,100,700);
			}
			//alert (current);//debug
			$.doTimeout(100, function(){ 
				showitemDetails(current,nmb_images,maxdiswidth);
				highlightItem(current,600);
			});
		});
	
	
		//next button clicked
		$('#nextOne').click(function(e){ // next item
			e.preventDefault(); // ignore default href action
			
			if (current < nmb_images-1) {
				++current;
				slideThumb(1); //move right
			} else {
				current=0; //move to first one
				//$fp_thumbScroller.stop().animate({'scrollLeft':'0px'},1000,'jswing');  //scroll to far left
				centerimagebyIndex(current,100,700); 
			}
			//alert(current);//debug
			$.doTimeout(100, function(){ 
				showitemDetails(current,nmb_images,maxdiswidth);
				highlightItem(current,600);
			});
		});
		
		
		$('#rememberitem').change(function(e){ // remember items
		//e.preventDefault(); // ignore default href action
		
			if ($(this).is(':checked')) {
				//alert ('remember item'); //debug
				$.updateCookie("wishlist",wishlistDelimiter,'').add ($(this).attr('value')); //update cookie with expire to end of session
				$('#item' + current + ' div:first-child').show();
			} else {
				//alert ('bin item'); //debug	
				$.updateCookie("wishlist",wishlistDelimiter,'').remove ($(this).attr('value')); //update cookie with expire to end of session
				$('#item' + current + ' div:first-child').hide();
			}
			$.post("dblist_update.php?list=wishlist"); //update DB
			
			$.favoritesToggle(); //toggle Favorites link state
		});
		
		
		
	
	}//end of function openGallery
	
	
	
	//move slider while the gallery is scrolling
	$fp_thumbScroller.scroll(function(){
		//alert($fp_thumbScroller.scrollLeft());
		$slider.slider('value',parseInt($fp_thumbScroller.scrollLeft(),10));
		//$('#handlevalue').val( $slider.slider('value')+'px'); //debug display current handel value as it scrolls
	});
	
	
	
	
	
	//convert itemnumber to obj and pass to centerImage
	function centerimagebyIndex(itemnumber,wait,speed){
		var $current=$('#item'+itemnumber); 
		//alert ($current.html());//debug
		centerImage($current,wait,speed);
	}
	
	
	//centers an image on slider and opens it if open is true
	function centerImage($obj,wait,speed){
		
		if ( $obj != null) {
			//alert ($obj.html());//debug
			var obj_left 	= $obj.position().left; //the offset left of the element
			var obj_center 	= obj_left + ($obj.width()/2); //the center of the element is its offset left plus half of its width
			//alert (obj_left);//debug
			
			var center = fp_thumbContainerCenter;
			
			//how much the scroller has scrolled already
			var currentscrollPos 	= parseFloat($fp_thumbScroller.scrollLeft(),10);
			//alert (currentscrollPos);//debug
			//so we know that in order to center the image,
			//we must scroll the center of the image minus the center of the screen,
			//and add whatever we have scrolled already
			var move = currentscrollPos + (obj_center - center);
			if(move != $fp_thumbScroller.scrollLeft()) { //new position != 
				$.doTimeout(wait, function(){ 
					$fp_thumbScroller.stop().animate({scrollLeft:move},speed,'jswing');
				});
			}
		}
	}  
	
	
	//slides the scroller one picture to the right or left
	function slideThumb(way){
		if(way==1){
			var $next = $fp_thumbScroller.find('.container:nth-child('+parseInt(gallery_idx+1)+')')
										 .find('.content:nth-child('+parseInt(current+1)+')');
			//alert($next);//debug
			if($next.length > 0)
				centerImage($next,0,600);
			else{
				--current;
				return;
			}	
		}
		else{
			var $prev = $fp_thumbScroller.find('.container:nth-child('+parseInt(gallery_idx+1)+')')
										 .find('.content:nth-child('+parseInt(current+1)+')');
			if($prev.length > 0)
				centerImage($prev,0,600);
			else{
				++current;
				return;
			}	
		}					
	}
	
	
	//make item closest to the center stays centered after stop sliding
	function checkClosest(){
		//var center 				= $(window).width()/2;
		var center		=fp_thumbContainerCenter;
		var current_distance 	= 99999999;
		var idx					= 0;	
		$container				= $fp_thumbScroller.find('.container:nth-child('+parseInt(gallery_idx+1)+')');
		//$.debug($container);//debug
		$container.find('.content').each(function(i){
			var $obj 		= $(this);
			var obj_left 	= $obj.position().left; //the offset left of the element
			var obj_center 	= obj_left + ($obj.width()/2); //the center of the element is its offset left plus half of its width
			var distance	= Math.abs(center-obj_center);
			if(distance < current_distance){
				current_distance 	= distance;
				idx					= i;
			}	
		});
		var $new_current 	= $container.find('.content:nth-child('+parseInt(idx+1)+')');
		current 			= $new_current.index();
		centerImage($new_current,100,500);
	}
	
	
	//highlight current item
	function highlightItem(itemnumber,delay) {
		var $current=$('#item'+itemnumber); 
		$fp_contentWrapper.children('div').each(function(){ //loop throught each item div
			//$(this).find('img').addClass('dim');
			//$(this).find('img').fadeTo('fast',0.7)
			//$(this).find('img').css('border', '1px solid #FFFFFF')
			$(this).find('img').removeClass('border_highlight');
		});
		$.doTimeout(delay, function(){  //highlight current
			//$current.find('img').removeClass('dim');
			//$current.find('img').fadeTo(300,1)
			//$current.find('img').css('border', '1px solid #FF3300')
			$current.find('img').addClass('border_highlight');
		});
	}
	
	
	
	
	
	//simulate auto click on default gallery
	//$("#load_this").delay(1000).queue(function(){
	//	$(this).trigger("click");
	//	$(this).dequeue();
	//});
	
});


function showitemDetails(itemIndex,num_items,detailmaxdiswidth) 
{
	
	//alert (itemIndex);//debug
	currentitemDetails=productitemdetailsJson[itemIndex];
	//$.debug(currentitemDetails);//debug
	
	//defind span highlight style for fields
	var highlight = '<span class=\"normal_8_bold\">'; 
	var endspan = '</span>'; 
	
	var newPrice=currentitemDetails.newprice/currentitemDetails.minqty;
	var currentPrice=(currentitemDetails.listprice/currentitemDetails.minqty);
	var button='add';  //defualt button
	
	var currentitemindex = $('.currentitemindex');
	var productname = $('.productname');
	var productcode = $('.productcode');
	var description = $('.description');
	var size = $('.size');
	var sizeremark = $('.sizeremark');
	var material = $('.material');
	var weight = $('.weight');
	var shipcost = $('.shipcost');
	var was = $('.was').hide();
	var now = $('.now').hide();
	var listprice = $('.listprice');
	var minqty = $('.minqty').hide();
	var showpricing = $('.showpricing');
	var showcurrency = $('.showcurrency');
	var showpricingPHP = $('#showpricingPHP').hide(); //hide php show price
	var nopricing = $('.nopricing').hide();
	var nopricingPHP = $('.nopricingPHP').hide();
	var promotion = $('.promotion').hide();
	var promotionPHP = $('.promotionPHP').hide();
	var largeviewlink = $('.largeviewlink')
	
	var add2cartBut = $('#add2cartBut');
	var inquireitemBut = $('#inquireitemBut');
	
	var rememberitem = $('#rememberitem');
	var wishlisted=inList("wishlist",currentitemDetails.productcode);
	var itemremembered = $('.itemremembered');
	
	var tellafriend = $('.tellafriend');
	var bookmarkitem = $('.bookmarkitem');
	
	var detailimageView = $('#detailimageView');
	var detailimage = $('#detailimage');
	
	var detailimageType;
	var detailimageWidth;
	var detailimageHeight;
	var largeview=false;
	
	
	var textfadeoutSpeed='fast';
	var textfadeoutTo=0.4;
	var textfadeinSpeed='slow';
	var textfadeinTo=1;
	
	
	
	//var converted=convertCurrency(currentPrice,'USD',localCurrency,2);
//	converted.success(function (data) {
//		alert (data);//debug
//	});
	
	
	
	//
	//product details
	//
	productname.fadeTo(textfadeoutSpeed,textfadeoutTo).html(currentitemDetails.productname).fadeTo(textfadeinSpeed,textfadeinTo);
	productcode.fadeTo(textfadeoutSpeed,textfadeoutTo).html(currentitemDetails.productcode).fadeTo(textfadeinSpeed,textfadeinTo); 
	description.fadeTo(textfadeoutSpeed,textfadeoutTo).html(currentitemDetails.description+"<br/><br/>").fadeTo(textfadeinSpeed,textfadeinTo); 
	
	if (currentitemDetails.size !='' && currentitemDetails.size!=null )
		size.fadeTo(textfadeoutSpeed,textfadeoutTo).html(highlight+currentitemDetails.sizekey+': '+endspan+currentitemDetails.size).fadeTo(textfadeinSpeed,textfadeinTo); 
	if (currentitemDetails.sizeremark!='' && currentitemDetails.sizeremark!=null)
		sizeremark.fadeTo(textfadeoutSpeed,textfadeoutTo).html(currentitemDetails.sizeremark+"<br/><br/>").fadeTo(textfadeinSpeed,textfadeinTo);
	if (currentitemDetails.material!='' && currentitemDetails.material!=null)
		material.fadeTo(textfadeoutSpeed,textfadeoutTo).html(highlight+'Clay: '+endspan+currentitemDetails.material+"<br/><br/>").fadeTo(textfadeinSpeed,textfadeinTo);
	
	if (currentitemDetails.weight!=0)
		weight.fadeTo(textfadeoutSpeed,textfadeoutTo).html(highlight+'Shipping weight: '+endspan+currentitemDetails.weight+" kg<br/>").fadeTo(textfadeinSpeed,textfadeinTo);
	if (currentitemDetails.flatshipping >0)
		shipcost.fadeTo(textfadeoutSpeed,textfadeoutTo).html(highlight+'Shipping cost: '+endspan+currentitemDetails.flatshipping+" (Fixed shipping item) <br/><br/>").fadeTo(textfadeinSpeed,textfadeinTo);
	if (currentitemDetails.flatshipping==0)
		shipcost.fadeTo(textfadeoutSpeed,textfadeoutTo).html(highlight+'Shipping cost: '+endspan+"Free <br/><br/>").fadeTo(textfadeinSpeed,textfadeinTo);	
	
	if (retail=='on' && currentitemDetails.price!=0 && !isLoggedin)
		$('.hideprice').fadeTo(textfadeinSpeed,textfadeinTo);
	
	
	//alert ('retail: '+retail+' ,price:'+currentitemDetails.price+' ,showPrices: '+showPrices+' ,isLoggedin: '+isLoggedin);//debug	
	if (retail=='on' && currentitemDetails.price!=0 && showPrices && isLoggedin) {
		showpricingPHP.hide();
		showpricing.show();
		nopricing.children().hide();
		nopricingPHP.hide();
		
		if (currentitemDetails.newprice!=0 ) {
			listprice.hide();
			was.show();
			$('.wasPrice').html(currentPrice+"<br/>");
			now.show(); 
			currentPrice=newPrice;
		} else {
			was.hide();
			now.hide();
		}
		//alert (parseFloat(currentPrice.toFixed(2)));
		
		listprice.fadeTo(textfadeoutSpeed,textfadeoutTo).html(currentPrice+"<br/>").fadeTo(textfadeinSpeed,textfadeinTo);
		if (showlocalcurrency=='on' && localCurrency!='USD' && localCurrency!='') {
			showcurrency.show();
			$('.convertedFlag').attr("src","Assests/images/"+localCurrency.toUpperCase()+".gif");
			$('.convertedCur').html("<img src='Assests/images/loading_s.gif' align='middle' style='margin-bottom:7px; display:inline-block; ' />");
			//$('.convertedCur').addClass("loading_S").attr("style","vertical-align:middle; margin-top:0px; display:inline-block;");
			
			convertCurrency(currentPrice,'USD',localCurrency,2, function(data){
				//alert (data);//debug
				$('.convertedCur').html(localCurrency+" "+data);
				//$('.convertedCur').removeClass("loading_S").removeAttr("style").doTimeout(1000).html(localCurrency+" "+data);
				
			});
		} else showcurrency.hide() //end show local currency
		
		if (currentitemDetails.minqty>1) {
			button='inquiry';
			minqty.show().html("(This is a wholesale item - minimum order quantity: "+currentitemDetails.minqty+" pieces)<br/>");
			showpricing.find('.minqty').html("(for a minimum order of "+currentitemDetails.minqty+" pieces)<br/>");
		} else {
			button='add';
			minqty.html("").hide();
			showpricing.find('.minqty').html("").hide();
		}
	
	} else {
		if (isLoggedin)	{
			button='inquiry';
			showpricing.hide();
			nopricing.show();
			nopricing.children().show().html("<br/>*Please contact us for pricing.<br/>");
		}
	}

	if (currentitemDetails.stock!='' && currentitemDetails.stock!=null) {
		promotion.show().html(currentitemDetails.stock+"<br/>");
	}
	if (currentitemDetails.promote!=0 && currentitemDetails.promotenote!='' && currentitemDetails.promotenote!=null) { 
		promotion.show().html(currentitemDetails.stock+"<br/>"+"Promotional item: "+currentitemDetails.promotenote+"<img src='Assests/images/!!.gif' align='texttop' /><br />");
	} 
	

	if (button=='add') {
		inquireitemBut.hide();
		if (retail=='on' && currentitemDetails.price!=0 && showPrices && isLoggedin) {
		add2cartBut.show().html("<a href=\"cart.php?page=details.php&sel="+currentitemDetails.category+"&sub="+currentitemDetails.subgroup+"&code="+currentitemDetails.productcode+"&shipsel="+currentitemDetails.destination+"&shipopt="+currentitemDetails.defaultship+"&act=add\" id='add2cart' class='button button2 submit' title='Add selected items to shopping cart'><img src='Assests/images/shoppingcart.gif' width='17' height='17' border='0' align='absmiddle' vspace='0'/>&nbsp;&nbsp;Add to Cart</a>");
		}
	
	} else if (button=='inquiry') {
		add2cartBut.hide();
		inquireitemBut.show().html("<a href=\"contact_us.php?page=details.php&sel="+currentitemDetails.category+"&sub="+currentitemDetails.subgroup+"&code="+currentitemDetails.productcode+"&shipsel="+currentitemDetails.destination+"&shipopt="+currentitemDetails.defaultship+"\" id='inquireitem' class='button submit' title='Back to previous page'>Contact us</a>");
	}

	//display remember item
	rememberitem.attr('value',currentitemDetails.productcode);
	rememberitem.attr('checked',wishlisted);  //check checkbox accordingly
	if (wishlisted) 
		$('#item' + itemIndex + ' div:first-child').show();
	else 
		$('#item' + itemIndex + ' div:first-child').hide();
	//
	
	tellafriend.find('a').attr("href","tellafriend.php?page=details.php&sel="+currentitemDetails.category+"&sub="+currentitemDetails.subgroup+"&code="+currentitemDetails.productcode ); 
	
	currentitemindex.html("&#8249; Item "+ (itemIndex+1) +" of "+ num_items +" &#8250;");
	
	//
	//end of product details
	//
	
	
	//pagetitle
	var pageTitle=String(currentitemDetails.productname);
	if (pageTitle.indexOf(" - ")) {
		var pageTitle = pageTitle.replace(/-/, '('+currentitemDetails.productcode.toUpperCase()+')'); //<-- this does't work
	} else {
		var pageTitle = pageTitle +" ("+currentitemDetails.productcode.toUpperCase()+") ";
	}
	pageTitle=currentitemDetails.categoryname+" : "+pageTitle;
	$(document).attr("title", "deeho.com - "+pageTitle);
	//
	
	
	//detail image
	var timestamp=new Date().getTime();
	
	$("#loading").show()
	$('#previousOne').hide();
	$('#nextOne').hide();
	//$('.overcast').fadeTo(10,0.5);
	
	$.post("image.php",{ 
		imagefile: 'Assests/products/teapot/'+currentitemDetails.productcode+currentitemDetails.imageformat,
		width: 500,
		watermark: 'on',
		forceheight: 'off',
		sel: currentitemDetails.category,
		source: 'j'
	}, function(data) {
		var trimData=trimCallback(data);
		//alert (trimData); //debug
		var postback=$.parseJSON(trimData); //parse returned json data and output javascript object
		//alert(postback.type); //debug
		detailimageType = postback.type; 
		detailimageWidth = postback.width; 
		detailimageHeight = postback.height;
		org_detailimageWidth = postback.org_width;  // of image file
		org_detailimageHeight = postback.org_height;  // of image file

		if (org_detailimageWidth>detailmaxdiswidth) //is org imagewidth > max display width
		{  
			//var scale = (detailmaxdiswidth/org_detailimageWidth);  
			if (org_detailimageWidth>(detailmaxdiswidth*1.3))   //php:$enlarge_threshold
				largeview=true; //offer enlarge if >enlarge_threshold  times of maxdiswidth
			else largeview=false;
		}
		//detailimageWidth_new= Math.ceil(org_detailimageWidth*scale);
		//detailimageHeight_new= Math.ceil(org_detailimageHeight*scale);
		//detailmaxdisheight= Math.ceil(org_detailimageHeight*(detailmaxdiswidth/org_detailimageWidth));
	
		
	
	}).complete(function() { 
			$('.image').remove(); //remove php image
			//$('.imageJ').fadeTo('fast',0.7).find('img'); //fade out old img
			//$('.overcast').fadeTo(10,0.7).animate({'height':(detailimageHeight+3)+'px'},500,'easeInOutSine')
			
			detailimageView.animate({'height':(detailimageHeight+3)+'px'},500,'easeInOutSine')  //easing: swing, jswing, easeOutBounce, easeOutSine, easeOutCubic, easeOutQuad easeInOutExpo
			detailimageView.find('#detailimage').css({width: detailimageWidth+'px', height: detailimageHeight+'px'});
			 
			
			
			$('.imageJ').find('img').addClass('dim').attr("src","/Assests/tempdata/tempImage."+detailimageType+"?"+timestamp).load(function(){ //timestamp forces browser to reload image each time
			//$('.imageJ').find('img').attr("src","/Assests/tempdata/tempImage."+detailimageType+"?"+timestamp).load(function(){ //timestamp forces browser to reload image each time	
				$('.imageJ').show().removeClass('dim');
				//$('.imageJ').show();
				
				//$('.overcast').fadeTo('fast',0);
				
				$.doTimeout(300, function(){
					$("#loading").hide();
					$('#previousOne').show();
					$('#nextOne').show();
				});
			});
			
			
			largeviewlink.show().find('a').removeAttr("onClick").attr("href","#" ); //remove php link
			if (largeview) { //largeview link
				largeviewlink.show().find('a').removeAttr("onClick").attr("href","#" );
				detailimage.find('a').attr("href","#" ).attr("title","Click to view larger image");
				$('.imageJ, .largeviewlinkClick').click(function(e){ // click to enlarge
					e.preventDefault(); // ignore default href action
					openNewWindow('detailspopup.php','image.php','Assests/products/'+currentitemDetails.category+'/'+currentitemDetails.productcode+'.'+detailimageType,
					0,'on','off',currentitemDetails.category,org_detailimageWidth,org_detailimageHeight,'deeho.com - '+pageTitle,780,570,
					currentitemDetails.categoryname,currentitemDetails.productcode.toUpperCase(),currentitemDetails.productname,currentitemDetails.size,currentitemDetails.material,currentitemDetails.weight,'');
				});
			} else {
				largeviewlink.hide();
				detailimage.find('a').removeAttr("href").removeAttr("title");
				$('.imageJ, .largeviewlinkClick').unbind("click"); //remove click event handler
			}
	
	
	
	});	//end detail image

}



function openNewWindow(Url,imagePage,imageName,width,waterMark,forceHeight,sel,imageWidth,imageHeight,title,winSizeX,winSizeY,Category,Code,Name,Size,Material,Weight,Text) 
{
	if (parseFloat(imageWidth)<parseFloat(winSizeX)) {winSizeX=parseFloat(imageWidth)+23}
	if (parseFloat(imageHeight)<parseFloat(winSizeY)) {winSizeY=parseFloat(imageHeight)+160}
	Url=Url+'?imagepage='+imagePage+'&imagename='+imageName+'&width='+width+'&watermark='+waterMark+'&forceheight='+forceHeight+'&sel='+sel+'&imagewidth='+imageWidth+'&imageheight='+imageHeight+'&title='+title+'&winsizex='+winSizeX+'&winsizey='+winSizeY+'&category='+Category+'&code='+Code+'&name='+Name+'&size='+Size+'&material='+Material+'&weight='+Weight+'&text='+Text
	//alert (Url);//debug
	winRef = window.open(Url,'NewWindow','width='+winSizeX+',height='+winSizeY+',left=10,top=10,scrollbars=1,menubar=0,status=0,toolbar=0,resizable=1'); 
	winRef.focus();
}




