// ====================== images ===============================
//  -------------------   images scolling   -------------------
var timer = null;
var animpanewidth = 0;
var animoffset_left = -5;
var animoffset_right = 5;
var curpos = 0;
function start_scrol(left,right,element,limita,speed)
{	
	animpanewidth = document.getElementById(element).offsetWidth;
	//alert(animpanewidth/2);
	if (left==1) {
	timer = setInterval("scrolling(1,0,"+limita+",'"+element+"')",speed);
	}
	if (right==1) {
	timer = setInterval("scrolling(0,1,"+limita+",'"+element+"')",speed);
	}
	
}
function stop_scrol(){
	clearInterval(timer);
}

function scrolling(left,right,limit,element)
{
	var elem = document.getElementById(element);

	if (left==1) {
		
		if(curpos + animoffset_left <= -animpanewidth+limit)
		{
				clearInterval(timer);
			
		}
			else
		{
			elem.style.left  = (curpos += animoffset_left)+'px';
		}
	}
	if (right==1) {
		//alert (elem.style.left + limit );
		if(elem.style.left == limit+'px')
		{
			clearInterval(timer);
			
		}
			else
		{
			elem.style.left  = (curpos += animoffset_right)+'px';
		}
	}
}

//  -------------------  END images scolling   -------------------
function Change_image_src(image1,big_picture_link,new_src) {
	var img1 = document.getElementById(image1);
	var img1_link = document.getElementById(big_picture_link);
	//alert (new_src);
	img1.src = new_src;
	img1_link.href = new_src;
}
//  --------------------------------------------------------------
function Show_Hiden(id_element) {
	var element = document.getElementById(id_element);
	if(element.style.display=='none'){
		element.style.display='block';
	}else{
		element.style.display='none';
	}
}
//  --------------------------------------------------------------
function Scrolling_marque($id){
	if  ($direction = 1){
		document.getElementById('content').direction="up";
			 
	}
	if ($direction = 2){
		document.getElementById('content').direction="down";
		alert(document.getElementById('content').direction);
	}
}
//  --------------------------------------------------------------
function printWindow(){
   bV = parseInt(navigator.appVersion)
   if (bV >= 4) window.print()
}
//  --------------------------------------------------------------
function addToBookmarks(url,title) {
  if (window.external && window.external.AddFavorite)    
   	window.external.AddFavorite(url,title);   
   // IE4 and later  
  else if (window.sidebar && window.sidebar.addPanel)    
   window.sidebar.addPanel(title,url,'');   
    // Gecko/firefox
}
//  --------------------------------------------------------------
function Make_AjQuery(items_array,change_html_div,timeout){
	var items=items_array.split(',');
	number_of_items = items.length;
	var _Href = '';
	var error = 0;
	for (i=0;i<=number_of_items-1;i++)
	{	
		if (document.getElementById(items[i]).value!=''){
			_Href = _Href+items[i]+'='+document.getElementById(items[i]).value+'&';
			//alert(document.getElementById(items[i]).value);
		}else{
			_Href='';
			error = 1;
		}
	}
	if(error==0){
		$href_len = _Href.length;
		_Href = _Href+'change_html_div='+change_html_div;
		var AjaxPath = 'index.php';
		$.ajax({type: "POST",url:AjaxPath,data:_Href,success:function(data){$('#jQuery').html(data);}});
		
	}

}
function Update_Bid_Timers(classa,str_id,class_two,bid_click,user){
	//clearTimeout();
	var bids = '';
	var clicked = '';
	var user_clicked = '';
	$(classa).each(function(){
		 var auctionId = $(this).attr('id');
		 if($('#'+auctionId).length){
			 bids = bids+auctionId.replace(str_id,'')+',';
		}
	});

	var class_t = classa.replace(class_two,'');
	$(class_t).each(function(){
		 var auctionId_two = $(this).attr('id');
		 if($('#'+auctionId_two).length){
			 bids = bids+auctionId_two.replace(str_id,'')+',';
		}
	});
	var lenght = bids.length;
	bids = bids.substr(0,(lenght-1));
	document.getElementById('Update_jQuery').value=bids;
	if(bid_click!= undefined){
		user_clicked='&user='+user;
		clicked='&clicked='+bid_click;
	}
	$.ajax({type: "POST",dataType:'json',url:'index.php',data:'Update_jQuery='+bids+clicked+user_clicked,success:function(data){

		$.each(data,function(i, item){
		
			if ($('#'+str_id+i).length){
				$('#'+str_id+i).html(item.time);
			}
			if (item.price!=$('#'+'products_price_'+i).html()){
				//alert($('#'+'products_price_'+i).html());
				$('#'+'products_price_'+i).html(item.price);
				AnimatePrice('#'+'products_price_'+i);
			}
			if ((item.credits!='') && (item.credits!=undefined)){
				$('#users_menu_box_bids').html('('+item.credits+')');
			}
			$('#'+'products_user_'+i).html(item.lastbider);
		})	
	}});
	
	if(bid_click==undefined){
		setTimeout("Update_Bid_Timers(\'.products_top_timer\',\'products_timer_\',\'_top\')",1000);
	}
}
function AnimatePrice(a){if($(a).attr("origFontSize")==null){$(a).attr("origFontSize",$(a).css("font-size"))}$(a).animate({fontSize:"+=250%"},300).animate({fontSize:$(a).attr("origFontSize")},600);}
//  --------------------------------------------------------------
function Move_Item_By_Scroll(name){
    var menuYloc = null;
    $(document).ready(function(){
        menuYloc = parseInt($(name).css("top").substring(0,$(name).css("top").indexOf("px")));
        $(window).scroll(function () {
	     //if ((menuYloc+$(document).scrollTop()>(menuYloc*3) )){
	     if ((menuYloc+$(document).scrollTop()>(menuYloc*3)+200)){
		 var offset = ($(document).scrollTop()-menuYloc-180)+"px";
	     }else{
		//var offset = (menuYloc+$(document).scrollTop())+"px";
		var offset = menuYloc+"px";
	     }
            $(name).animate({top:offset},{duration:500,queue:false});
        });
    }); 
}
//  --------------------------------------------------------------
