$(document).ready( function()
{
	var $panel_ID	= (helper_get_urlvars()['PANELID'] == undefined)?0:parseInt(helper_get_urlvars()['PANELID']);
	$("#accordion").accordion(
	{ 
		active: $panel_ID
	});
	//---- ACTIVATE SCROLLER
	sidebar_scroller_equipment("#sidebar_scroller_equipment",15,5000);

	//---- PAGE SPECIFIC SCRIPTS
	if (helper_get_urlvars()['PAGE'] == 4)
		gallery_display();
		
});
var $url_variables				= [];
//---- HELPER FUNCTIONS
function helper_get_urlvars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}

var $scroller_current_item	= 0;
function sidebar_scroller($div_name,$item_number,$timeout)
{
	if ($scroller_current_item == 0)
	{
		for (var $i =0; $i <= $item_number;$i++)
			$($div_name+" img:nth-child("+$i+")").fadeOut();
		$scroller_current_item++;		
	}
	else
	{
		$($div_name+" img:nth-child("+$scroller_current_item+")").fadeOut(800);
		$scroller_current_item	= ($scroller_current_item < $item_number )? ($scroller_current_item+1): 1;
	}
	$($div_name+" img:nth-child("+$scroller_current_item+")").fadeIn(800);
	setTimeout ( "sidebar_scroller('"+$div_name+"',"+$item_number+","+$timeout+")" , $timeout );
}

var $scroller_current_equipment_item	= 0;
function sidebar_scroller_equipment($div_name,$item_number,$timeout)
{
	if ($scroller_current_equipment_item == 0)
	{
		for (var $i =0; $i <= $item_number;$i++)
			$($div_name+" img:nth-child("+$i+")").fadeOut();
		$scroller_current_equipment_item++;		
	}
	else
	{
		$($div_name+" img:nth-child("+$scroller_current_equipment_item+")").fadeOut(800);
		$scroller_current_equipment_item	= ($scroller_current_equipment_item < $item_number )? ($scroller_current_equipment_item+1): 1;
	}
	$($div_name+" img:nth-child("+$scroller_current_equipment_item+")").fadeIn(800);
	setTimeout ( "sidebar_scroller_equipment('"+$div_name+"',"+$item_number+","+$timeout+")" , $timeout );
}




//---- ALLIED SCROLLER
var $toggle		= 0;
function allied_scroll()
{
	if ($toggle == 0)
	{
		$("#aliado1").fadeOut();
		$("#aliado2").fadeOut();
		$("#aliado3").fadeOut();
		$("#aliado4").fadeOut();
		$("#aliado5").fadeIn();
		$("#aliado6").fadeIn();
		$("#aliado7").fadeIn();
		$("#aliado8").fadeIn();
		$("#aliado9").fadeOut();
		$("#aliado10").fadeOut();
		$toggle = 1;
	}
	else if ($toggle == 1)
	{
		$("#aliado1").fadeOut();
		$("#aliado2").fadeOut();
		$("#aliado3").fadeOut();
		$("#aliado4").fadeOut();
		$("#aliado5").fadeOut();
		$("#aliado6").fadeOut();
		$("#aliado7").fadeOut();
		$("#aliado8").fadeOut();
		$("#aliado9").fadeIn();
		$("#aliado10").fadeIn();
		$toggle = 2;
	}
	else if ($toggle == 2)
	{
		$("#aliado1").fadeIn();
		$("#aliado2").fadeIn();
		$("#aliado3").fadeIn();
		$("#aliado4").fadeIn();
		$("#aliado5").fadeOut();
		$("#aliado6").fadeOut();
		$("#aliado7").fadeOut();
		$("#aliado8").fadeOut();
		$("#aliado9").fadeOut();
		$("#aliado10").fadeOut();
		$toggle = 0;
	}
}

//---- GALLERY ITEMS
var $gallery_page_ID			= 0;
var $gallery_item_count		= 1;
var $gallery_array				= [];
function gallery_display()
{
	//---- INGRESO DE PRODUCTOS ACA EN UN ARRAY
	$gallery_array						= [];
	var $gallery_json_array		= eval('('+xajax_gallery_json_array($gallery_page_ID)+')');
	$gallery_item_count				= $gallery_json_array.rowcount;
	$gallery_array						= $gallery_json_array;			
	var $result							= "";
	setTimeout("gallery_display_timeout("+0+")",300 );
}
function gallery_display_timeout($i)
{
	var		$current_ID		= $gallery_array[$i].field0;
	$html		= 	'<div class="item" id="clientes_item'+$i+'"><img src="./userContent/CMS/'+$gallery_array[$i].field2+'" alt="'+$gallery_array[$i].field1+'" ></div>';

	$("#clientes_gallery").append($html);
	$("#clientes_item"+$i).hide();
	$("#clientes_item"+$i).fadeIn(800);
	
	if ($i < ($gallery_item_count - 1))
	{
		$i++;		
		setTimeout("gallery_display_timeout("+$i+")",100 );
	}
}
function gallery_next_page($i)
{
 	if ($i > 0)
	{
		$("#clientes_item"+$i).fadeOut();
		$i--;
		setTimeout("gallery_next_page("+$i+")",80 );
	}
	else
	{
		$("#clientes_gallery").html("");
		if ($gallery_item_count == 16)
			$gallery_page_ID++;
		else	
			$gallery_page_ID = 0;
		gallery_display();
	}
}

function recelca_toggle_form()
{
	if ($("#checkbox_toggle").attr('checked') == true )
	{
		$(".cotizaciones_form02").fadeIn();
		$('.checkbox_toggle_form01').fadeOut();
		$("#ASTEGform_dir").attr("value","RECICLAJE");
	}
	else
	{
		$(".cotizaciones_form02").fadeOut();		
		$('.checkbox_toggle_form01').fadeIn();
		$("#ASTEGform_dir").attr("value","VENTAS");
	}
}

