var t
var addmouse=false;
function fixcenter()
{
	if($('#imgload').css('display')=='block'){
		 if($('#imgload').attr('height')<$(window).height())
		 	$('#imgload').css("top", (($(window).height() - $('#imgload').attr('height')) / 2) + $(window).scrollTop() + "px");
		 else{
			$('#imgload').css("top", $(window).scrollTop() + "px");
			clearTimeout(t);
			return;
		}		
		if($('#imgload').attr('width')<$(window).width())
		 $('#imgload').css("left", (($(window).width() - $('#imgload').attr('width')) / 2) + $(window).scrollLeft() + "px");
		else{
			$('#imgload').css("left", "0px");
			clearTimeout(t);	
			return;
		}		
	}
	t=setTimeout("fixcenter()",100);
}

function fixwidth(){
	var lenimg = $("#myImageFlow_images img").length;
	
	//alert(len1)
	var len=0;
	
	$("#div").html('');
	
	$('#myImageFlow_images').find('img').each(function(){
		if($(this).css('visibility')=='visible')
			len++;
			
	})
	var i=0;
	var imgs=new Array();
	$('#myImageFlow_images').find('img').each(function(){
		if($(this).css('visibility')=='visible'){
			//alert($(this).css('width') + "__" + $(this).css('height') + "__" + $(this).css('left') + "__" + $(this).css('top'))
			//$("#div").append(this.id + "_" + $(this).css('width') + "_" + $(this).css('left') + "<br>")
			i++;
			if(len==5 || len==7){
				imgs[i]=this;
			}	
			
		}
		
		if(addmouse==false){
			$(this).mouseover(function() {
			  
				timeimg=false;
				
				if(runimg==0 || runimg==2){
					$(this).animate({"top": "+=10px"}, "fast")
					runimg=0;	
				}	
			}).mouseout(function() {
			  	timeimg=true;
				if(runimg==0){
					//$(this).animate({"top": "-=10px"}, "fast");	
					$(this).animate({"top": "-=10px"}, "fast", function() {
						
					});
				}
				
			});
			
		}
		
	})
	addmouse=true;	
	
	var L2, W2, L3, W3, L4, W4, L5, W5, L6, W6, L, W;
	
	if(len==5){
		L1=parseFloat($(imgs[2]).css('left').replace('px',''));
		W1=parseFloat($(imgs[2]).css('width').replace('px',''));
		
		L3=parseFloat($(imgs[4]).css('left').replace('px',''));
		W3=parseFloat($(imgs[4]).css('width').replace('px',''));
		
		L2=parseFloat($(imgs[3]).css('left').replace('px',''));
		W2=parseFloat($(imgs[3]).css('width').replace('px',''));
		
		W=((L3- (L1+W1))/2)+(L1+W1)-(W2/2)
		//$(imgs[3]).css('left', W + 'px');
		$(imgs[3]).animate({"left": (W) + "px"}, "slow")
		$(imgs[2]).animate({"left": (L1-1) + "px"}, "slow")
	}else if(len==7){
		L2=parseFloat($(imgs[2]).css('left').replace('px',''));
		W2=parseFloat($(imgs[2]).css('width').replace('px',''));
		
		L3=parseFloat($(imgs[3]).css('left').replace('px',''));
		W3=parseFloat($(imgs[3]).css('width').replace('px',''));
		
		L4=parseFloat($(imgs[4]).css('left').replace('px',''));
		W4=parseFloat($(imgs[4]).css('width').replace('px',''));
		
		L5=parseFloat($(imgs[5]).css('left').replace('px',''));
		W5=parseFloat($(imgs[5]).css('width').replace('px',''));
		
		L6=parseFloat($(imgs[6]).css('left').replace('px',''));
		W6=parseFloat($(imgs[6]).css('width').replace('px',''));
		
		if (L5+W5<L6){
			W= (L6 - (L5+W5)) + L5+3
			//alert(L6 +'_'+(L5+W5)+'_'+W)
			//$(imgs[5]).css('left', W + 'px');
			$(imgs[5]).animate({"left": W + "px"}, "slow")
			L5=W;
		}

		if(L2+W2<L3){
			W= (L2+W2)-3
			$(imgs[3]).animate({"left": W + "px"}, "slow")
			L3=W;
		}

	
		W=((L5- (L3+W3))/2)+(L3+W3)-(W4/2)
//					//$(imgs[3]).css('left', W + 'px');
		$(imgs[4]).animate({"left": W + "px"}, "slow")
	}
	
}

jQuery.fn.center = function () {
    this.css("position","absolute");
    this.css("top", (($(window).height() - this.outerHeight()) / 2) + $(window).scrollTop() + "px");
    this.css("left", (($(window).width() - this.outerWidth()) / 2) + $(window).scrollLeft() + "px");
    return this;
}

 function formatCurrency(num) 
{
    num = num.toString().replace(/\$|\,/g,'');
    if(isNaN(num))
    num = "0";
    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num*100+0.50000000001);
    cents = num%100;
    num = Math.floor(num/100).toString();
    if(cents<10)
    cents = "0" + cents;
    for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
    num = num.substring(0,num.length-(4*i+3))+','+
    num.substring(num.length-(4*i+3));
    //return (((sign)?'':'-') +  num + '.' + cents);
    return (((sign)?'':'-') +  num );
}

    // Replaces all instances of the given substring.
String.prototype.replaceAll = function(
strTarget, // The substring you want to replace
strSubString // The string you want to replace in.
){
var strText = this;
var intIndexOfMatch = strText.indexOf( strTarget );
 
// Keep looping while an instance of the target string
// still exists in the string.
while (intIndexOfMatch != -1){
// Relace out the current instance.
strText = strText.replace( strTarget, strSubString )
 
// Get the index of any next matching substring.
intIndexOfMatch = strText.indexOf( strTarget );
}
 
// Return the updated string with ALL the target strings
// replaced out with the new substring.
return( strText );
} 
