var dealerList;

$(document).ready(function()
{
	dealerList = $("#dealersearch").jLook();
	
	
	$(".selectlist ul li").click(function(){
		var index = $(this).attr("id");
		showDealerInfo( parseInt(index) );
	});
	
	$("#dealerlist table").Hide();
	
	
	// select event handling
	//handle several events of the manipulated selectbox
	$('.jLookSelectWrapper li').hover(function(){
		$(this).addClass('li_hover');		
		},
		function(){
		$(this).removeClass('li_hover');				
	});

	$('.jLookSelectWrapper span').text('Seleccione...');				

	$('.jLookSelectWrapper ul li').click(function(){
		
		$('#selectvalue').attr('value', $(this).text());
		var index = parseInt( $(this).attr('id') );
		$(this).parent().parent().parent().parent().parent().find('span').text($(this).text());
		$(this).parent().parent().parent().parent().parent().find('.jLookSelectOpen').click();
		
		$(this).parent().parent().parent().parent().parent().find('select').find('option').each( function(){
			$(this).attr("selected" , "");
		});
		
		$(this).parent().parent().parent().parent().parent().find('select').find('option').eq(index).attr("selected" , "selected");
		
		// call to flash-map
		provinceSelected( index );
	});
	
});

function selectDealerFromList( idx ){
	var i = idx < 10 ? "0"+idx : idx;
	$('.jLookSelectWrapper ul li').each( function(){
		var index = $(this).attr("id");
		if( index == i ){
			$(this).click();
			$(this).parent().parent().parent().parent().parent().find('.jLookSelectOpen').click();
		}	
	});
		window.location='dealersearch.aspx?prov=' + i; 
}

function showDealerInfo( index ){
	
	$("#dealerlist table").hide();
	$('#dealerlist').find('#'+index).show();

	
}

function thisMovie(movieName) {
         if (navigator.appName.indexOf("Microsoft") != -1) {
             return window[movieName];
         } else {
             return document[movieName];
         }
     }


function provinceSelected(value) {
        thisMovie("flashcontent").provinceSelected(value);
}
