var index_supplier = 1, index_product = 1;
var product_count_gbl, listing_count_gbl, country_color_gbl;
var this_domain = document.domain ;
if (this_domain.indexOf("192.") > -1) this_domain = this_domain + "/dirs/propertydir";
this_domain = "http://"+this_domain;

function next_click_wegiet(curr,el)
{
	$(".product_widget_link").css({"color":"#b4b4b4"})
	product_count_gbl = parseInt(product_count_gbl);

	if(curr > -1)
	{	
		if(product_count_gbl==25)
		{
			if(curr == 25)
				curr = 0;
			else if(curr == 30)
				curr = 5;
		}
		else if(product_count_gbl==20)
		{
			if(curr == 20)
				curr = 0;
			else if(curr == 25)
				curr = 5;
		}
		else if(product_count_gbl==15)
		{
			if(curr == 15)
				curr = 0;
			else if(curr == 20)
				curr = 5;
		}
		else if(product_count_gbl==10)
		{
			if(curr == 15)
				curr = 5;
			else if(curr == 10)
				curr = 0;
		}
		
		document.getElementById((curr+1)+ "_products").style.color = country_color_gbl;
		index_product = curr+1;
		var load_image = "<div style='width:100%; text-align:center;'><img border='0' style='margin-top:10px;' src='" + this_domain + "/admin/images/loading.gif' /></div>";   
		showvalue = parseInt(curr);
	    var mycurr1 = curr;
		
		var mycuur_html =  $('a.jcar_prod_img_' + mycurr1).html();
		
		if(mycuur_html.indexOf('loading.gif') != -1)
		{   
			
			$('a.jcar_prod_img_' + mycurr1).html(load_image);
			var value1  =  $('input.jcar_prod_input_'+ mycurr1).val();
			
			var mycurr2 = mycurr1 + 1;
			$('a.jcar_prod_img_' + mycurr2).html(load_image);
			var value2  =  $('input.jcar_prod_input_'+ mycurr2).val();
			
			var mycurr3 = mycurr1 + 2;
			$('a.jcar_prod_img_' + mycurr3).html(load_image);
			var value3  =  $('input.jcar_prod_input_'+ mycurr3).val();

			var mycurr4 = mycurr1 + 3;
			$('a.jcar_prod_img_' + mycurr4).html(load_image);
			var value4  =  $('input.jcar_prod_input_'+ mycurr4).val();				
			
			var mycurr5 = mycurr1 + 4;
			$('a.jcar_prod_img_' + mycurr5).html(load_image);
			var value5  =  $('input.jcar_prod_input_'+ mycurr5).val();				

			$('a.jcar_prod_img_' + mycurr1).html('<img src="'+value1+'" border="0" align="center" vspace="5"/>');
			$('a.jcar_prod_img_' + mycurr2).html('<img src="'+value2+'" border="0" align="center" vspace="5"/>');
			$('a.jcar_prod_img_' + mycurr3).html('<img src="'+value3+'" border="0" align="center" vspace="5"/>');
			$('a.jcar_prod_img_' + mycurr4).html('<img src="'+value4+'" border="0" align="center" vspace="5"/>');																																
			$('a.jcar_prod_img_' + mycurr5).html('<img src="'+value5+'" border="0" align="center" vspace="5"/>');																																
		}
	}
}


function prev_click_wegiet(curr)
{
	$(".product_widget_link").css({"color":"#b4b4b4"})

	product_count_gbl = parseInt(product_count_gbl);
	if(product_count_gbl==25)
	{
			if(curr == 5 || (curr > product_count_gbl))
				curr = (product_count_gbl-5)
			else if(curr == 0)
				curr = (product_count_gbl-10)
			else if(curr == 20)
				curr = (product_count_gbl-15)
			else if(curr == 15)
				curr = (product_count_gbl-20)
			else if(curr == 25)
				curr = (product_count_gbl-10)
			else
			{
				document.getElementById(1+ "_products").style.color = country_color_gbl;
				return;
			}
	}
	else if(product_count_gbl==20)
	{
		if(curr == 5)
			curr = 15;
		else if(curr == 0)
			curr = 10;
		else if(curr == 15)
			curr = 5;
		else if(curr == 10)
			curr = 0;
		else if(curr == 25)
			curr = 15;
		else if(curr == 20)
			curr = 10;	
	}
	else if(product_count_gbl==15)
	{
		if(curr == 5)
			curr = 10;
		else if(curr == 0)
			curr = 5;
		else if(curr == 10)
			curr = 0;
		else if(curr == 15)
			curr = 5;
		else if(curr == 20)
			curr = 10;
	}
	else if(product_count_gbl==10)
	{
		if(curr == 5)
			curr = 5;
		else if(curr == 0)
			curr = 0;
		else if(curr == 15)
			curr = 5;
		else if(curr == 10)
			curr = 0;
	}
	
	document.getElementById((curr+1)+ "_products").style.color = country_color_gbl;
	index_product = curr+1;		
	var load_image = "<div style='width:100%; text-align:center;'><img border='0' style='margin-top:10px;' src='" + this_domain + "/admin/images/loading.gif' /></div>";   
	showvalue = parseInt(curr);
		var mycurr1 = curr;            
	

	var mycuur_html =  $('a.jcar_prod_img_' + mycurr1).html();
	/*mycuur_html = mycuur_html.replace(/ /g,''); 
	mycuur_html = mycuur_html.replace(/\r/g,''); 
	mycuur_html = mycuur_html.replace(/\n/g,''); 				
	mycuur_html = mycuur_html.replace(/\t/g,''); 								*/

	if(mycuur_html.indexOf('loading.gif') != -1)
	{   
		$('a.jcar_prod_img_' + mycurr1).html(load_image);
		var value1  =  $('input.jcar_prod_input_'+ mycurr1).val();
		
		var mycurr2 = mycurr1 + 1;
		$('a.jcar_prod_img_' + mycurr2).html(load_image);
		var value2  =  $('input.jcar_prod_input_'+ mycurr2).val();
		
		var mycurr3 = mycurr1 + 2;
		$('a.jcar_prod_img_' + mycurr3).html(load_image);
		var value3  =  $('input.jcar_prod_input_'+ mycurr3).val();

		var mycurr4 = mycurr1 + 3;
		$('a.jcar_prod_img_' + mycurr4).html(load_image);
		var value4  =  $('input.jcar_prod_input_'+ mycurr4).val();				

		var mycurr5 = mycurr1 + 4;
		$('a.jcar_prod_img_' + mycurr5).html(load_image);
		var value5  =  $('input.jcar_prod_input_'+ mycurr5).val();				


		$('a.jcar_prod_img_' + mycurr1).html('<img src="'+value1+'" border="0" align="center" vspace="5"/>');
		$('a.jcar_prod_img_' + mycurr2).html('<img src="'+value2+'" border="0" align="center" vspace="5"/>');
		$('a.jcar_prod_img_' + mycurr3).html('<img src="'+value3+'" border="0" align="center" vspace="5"/>');
		$('a.jcar_prod_img_' + mycurr4).html('<img src="'+value4+'" border="0" align="center" vspace="5"/>');																																		
		$('a.jcar_prod_img_' + mycurr5).html('<img src="'+value5+'" border="0" align="center" vspace="5"/>');																																		
	}
}

/*###############################################################################################################################*/

function next_click_wegiet_listing(curr)
{
	$(".supplier_widget_link").css({"color":"#b4b4b4"})
	listing_count_gbl = parseInt(listing_count_gbl);

	if(curr > -1)
	{		
		if(listing_count_gbl==25)
		{
			if(curr == 25)
				curr = 0;
			else if(curr == 30)
				curr = 5;
		}
		else if(listing_count_gbl==20)
		{
			if(curr == 20)
				curr = 0;
			else if(curr == 25)
				curr = 5;
		}
		else if(listing_count_gbl==15)
		{
			if(curr == 15)
				curr = 0;
			else if(curr == 20)
				curr = 5;
		}
		else if(listing_count_gbl==10)
		{
			if(curr == 15)
				curr = 5;
			else if(curr == 10)
				curr = 0;
		}
		
		document.getElementById((curr+1)+ "_supplier").style.color = country_color_gbl;
		index_supplier = curr+1;
		var load_image = "<div style='width:100%; text-align:center;'><img border='0' style='margin-top:10px;' src='" + this_domain + "/admin/images/loading.gif' /></div>";   
		showvalue = parseInt(curr);
	    var mycurr1 = curr;
		
		var mycuur_html =  $('a.jcar_listing_img_' + mycurr1).html();
		/*mycuur_html = mycuur_html.replace(/ /g,''); 
		mycuur_html = mycuur_html.replace(/\r/g,''); 
		mycuur_html = mycuur_html.replace(/\n/g,''); 				
		mycuur_html = mycuur_html.replace(/\t/g,''); 								*/

		if(mycuur_html.indexOf('loading.gif') != -1)
		{   
			$('a.jcar_listing_img_' + mycurr1).html(load_image);
			var value1  =  $('input.jcar_listing_input_'+ mycurr1).val();
			
			var mycurr2 = mycurr1 + 1;
			$('a.jcar_listing_img_' + mycurr2).html(load_image);
			var value2  =  $('input.jcar_listing_input_'+ mycurr2).val();
			
			var mycurr3 = mycurr1 + 2;
			$('a.jcar_listing_img_' + mycurr3).html(load_image);
			var value3  =  $('input.jcar_listing_input_'+ mycurr3).val();

			var mycurr4 = mycurr1 + 3;
			$('a.jcar_listing_img_' + mycurr4).html(load_image);
			var value4  =  $('input.jcar_listing_input_'+ mycurr4).val();				
			
			var mycurr5 = mycurr1 + 4;
			$('a.jcar_listing_img_' + mycurr5).html(load_image);
			var value5  =  $('input.jcar_listing_input_'+ mycurr5).val();				

			$('a.jcar_listing_img_' + mycurr1).html('<img src="'+value1+'" border="0" align="center" vspace="5"/>');
			$('a.jcar_listing_img_' + mycurr2).html('<img src="'+value2+'" border="0" align="center" vspace="5"/>');
			$('a.jcar_listing_img_' + mycurr3).html('<img src="'+value3+'" border="0" align="center" vspace="5"/>');
			$('a.jcar_listing_img_' + mycurr4).html('<img src="'+value4+'" border="0" align="center" vspace="5"/>');																																	
			$('a.jcar_listing_img_' + mycurr5).html('<img src="'+value5+'" border="0" align="center" vspace="5"/>');																																	
		}
	}
}


function prev_click_wegiet_listing(curr)
{
	$(".supplier_widget_link").css({"color":"#b4b4b4"})
		
	listing_count_gbl = parseInt(listing_count_gbl);
	if(listing_count_gbl==20)
	{
			if(curr == 5 || (curr > listing_count_gbl))
				curr = (listing_count_gbl-5)
			else if(curr == 0)
				curr = (listing_count_gbl-10)
			else if(curr == 20)
				curr = (listing_count_gbl-15)
			else if(curr == 15)
				curr = (listing_count_gbl-20)
			else if(curr == 25)
				curr = (listing_count_gbl-10)
			else
			{
				document.getElementById(1+ "_supplier").style.color = country_color_gbl;
				return;
			}
	}
	else if(listing_count_gbl==20)
	{
		if(curr == 5)
			curr = 15;
		else if(curr == 0)
			curr = 10;
		else if(curr == 15)
			curr = 5;
		else if(curr == 10)
			curr = 0;
		else if(curr == 25)
			curr = 15;
		else if(curr == 20)
			curr = 10;	
	}
	else if(listing_count_gbl==15)
	{
		if(curr == 5)
			curr = 10;
		else if(curr == 0)
			curr = 5;
		else if(curr == 10)
			curr = 0;
		else if(curr == 15)
			curr = 5;
		else if(curr == 20)
			curr = 10;
	}
	else if(listing_count_gbl==10)
	{
		if(curr == 5)
			curr = 5;
		else if(curr == 0)
			curr = 0;
		else if(curr == 15)
			curr = 5;
		else if(curr == 10)
			curr = 0;
	}	
	
	document.getElementById((curr+1)+ "_supplier").style.color = country_color_gbl;
	index_supplier = curr+1;	
	var load_image = "<div style='width:100%; text-align:center;'><img border='0' style='margin-top:10px;' src='" + this_domain + "/admin/images/loading.gif' /></div>";   
	showvalue = parseInt(curr);
		var mycurr1 = curr;            
	

	var mycuur_html =  $('a.jcar_listing_img_' + mycurr1).html();
	/*mycuur_html = mycuur_html.replace(/ /g,''); 
	mycuur_html = mycuur_html.replace(/\r/g,''); 
	mycuur_html = mycuur_html.replace(/\n/g,''); 				
	mycuur_html = mycuur_html.replace(/\t/g,''); 								*/

	if(mycuur_html.indexOf('loading.gif') != -1)
	{   
		$('a.jcar_listing_img_' + mycurr1).html(load_image);
		var value1  =  $('input.jcar_listing_input_'+ mycurr1).val();
		
		var mycurr2 = mycurr1 + 1;
		$('a.jcar_listing_img_' + mycurr2).html(load_image);
		var value2  =  $('input.jcar_listing_input_'+ mycurr2).val();
		
		var mycurr3 = mycurr1 + 2;
		$('a.jcar_listing_img_' + mycurr3).html(load_image);
		var value3  =  $('input.jcar_listing_input_'+ mycurr3).val();

		var mycurr4 = mycurr1 + 3;
		$('a.jcar_listing_img_' + mycurr4).html(load_image);
		var value4  =  $('input.jcar_listing_input_'+ mycurr4).val();				
		
		var mycurr5 = mycurr1 + 4;
		$('a.jcar_listing_img_' + mycurr5).html(load_image);
		var value5  =  $('input.jcar_listing_input_'+ mycurr5).val();				

		$('a.jcar_listing_img_' + mycurr1).html('<img src="'+value1+'" border="0" align="center" vspace="5"/>');
		$('a.jcar_listing_img_' + mycurr2).html('<img src="'+value2+'" border="0" align="center" vspace="5"/>');
		$('a.jcar_listing_img_' + mycurr3).html('<img src="'+value3+'" border="0" align="center" vspace="5"/>');
		$('a.jcar_listing_img_' + mycurr4).html('<img src="'+value4+'" border="0" align="center" vspace="5"/>');																																	
		$('a.jcar_listing_img_' + mycurr5).html('<img src="'+value5+'" border="0" align="center" vspace="5"/>');																																	
	}
}


/*###############################################################################################################################*/

function index_functions(lead_limit_sell, lead_limit_buy, country_color, product_count, listing_count)
{	
	if(document.getElementById("hdn_product_count"))
	{
		product_count = document.getElementById("hdn_product_count").value;
	}

	if(document.getElementById("hdn_listing_count"))
	{
		listing_count = document.getElementById("hdn_listing_count").value;
	}
	
	if(document.getElementById("hdn_lead_sell_count"))
	{
		lead_limit_sell = document.getElementById("hdn_lead_sell_count").value;
	}
	
	if(document.getElementById("hdn_lead_buy_count"))
	{
		lead_limit_buy = document.getElementById("hdn_lead_buy_count").value;
	}

	product_count_gbl = product_count, listing_count_gbl = listing_count, country_color_gbl = country_color;	

	if(lead_limit_sell > 6) {
	$(function() {
			$(".anyClass1").jCarouselLite({
		    vertical: true,
					visible: 7,
					auto: 800,
					speed:500,
					mouseover: true
				
			});
	});
}

 if(lead_limit_buy > 6) { 
	$(function() {
			$(".anyClass2").jCarouselLite({
		    vertical: true,
					visible: 7,
					auto: 800,
					speed:500,
					mouseover: true
				
			});
	})
}
	
	//window.onload = setHeight; 
		
	function setHeight()
	{	
		if(listing_count >= 10)
		{
			document.getElementById("1_supplier").style.color = country_color;
		}

		if(product_count >= 10)
		{
			document.getElementById("1_products").style.color = country_color;
		}
	
		var anyClass1 = document.getElementById('anyClass1').style.height;
		var anyClass2 = document.getElementById('anyClass2').style.height;
			
		if(parseInt(anyClass1) > parseInt(anyClass2))
		{
			document.getElementById('anyClass2').style.height = anyClass1;
		}
		else if(parseInt(anyClass2) > parseInt(anyClass1))
		{
			document.getElementById('anyClass1').style.height = anyClass2;
		}	
	}
		
	$(function() {
		$(".pop_products").jCarouselLite({
			btnNext: ".next_products",
			btnPrev: ".prev_products",
			speed:1100,
			visible: 5,
			scroll: 5,
			next_btn_function: "next_click_wegiet",
			prev_btn_function: "prev_click_wegiet",
			btnGo:
			[".1_products", ".2_products",
			".3_products", ".4_products",
			".5_products", ".6_products",
			".7_products", ".8_products",
			".9_products", ".10_products",
			".11_products", ".12_products",
			".13_products", ".14_products",
			".15_products", ".16_products",
			".17_products", ".18_products",			
			".19_products", ".20_products",
			".21_products", ".22_products",
			".23_products", ".24_products",
			".25_products"]
			
		});
	});
	
	$(".product_widget_link").mouseover(function(){
		element_id = this.id;
		element_id = element_id.split("_");
		element_id = element_id[0];
		if(index_product != element_id)
			this.style.color = "#f56655";
	});
	
	$(".product_widget_link").mouseout(function(){
		element_id = this.id;
		element_id = element_id.split("_");
		element_id = element_id[0];
		if(index_product != element_id)
			this.style.color = "#b4b4b4";
	});	
	
	$(function() {
		$(".pop_supplier").jCarouselLite({
			btnNext: ".next_supplier",
			btnPrev: ".prev_supplier",
			speed:1100,
			visible: 5,
			scroll: 5,
			//circular: false
			next_btn_function: "next_click_wegiet_listing",
			prev_btn_function: "prev_click_wegiet_listing",	
			btnGo:
			[".1_supplier", ".2_supplier",
			".3_supplier", ".4_supplier",
			".5_supplier", ".6_supplier",
			".7_supplier", ".8_supplier",
			".9_supplier", ".10_supplier",
			".11_supplier", ".12_supplier",
			".13_supplier", ".14_supplier",
			".15_supplier", ".16_supplier",
			".17_supplier", ".18_supplier",			
			".19_supplier", ".20_supplier",
			".21_supplier", ".22_supplier",
			".23_supplier", ".24_supplier",
			".25_supplier"]
		});
	});
	
	$(".supplier_widget_link").mouseover(function(){
		element_id = this.id;
		element_id = element_id.split("_");
		element_id = element_id[0];
		if(index_supplier != element_id)
			this.style.color = "#f56655";
	});
	
	$(".supplier_widget_link").mouseout(function(){
		element_id = this.id;
		element_id = element_id.split("_");
		element_id = element_id[0];
		if(index_supplier != element_id)
			this.style.color = "#b4b4b4";
	});
}