// JavaScript Document for homepage

var lang = new Array();
lang[1] = new Array();									 
lang[2]	=	new Array();	

lang[1]['all'] = 'All';
lang[2]['all'] = 'Toate';

var locales_id = null;
function init()
{	
	locales_id = $('#locales_id').val();
	$('#brand_search').empty().html('<select name="brand" id="brand_sear" onchange="brand_change();"><option value="all">---------- '+lang[locales_id]['all']+' ----------</option></select>');
	$('#model_search').empty().html('<select name="model" id="model_sear" ><option value="all">---------- '+lang[locales_id]['all']+' ----------</option></select>');	
}

function initSearchForm()
{
	locales_id = $('#locales_id').val();
	
	$('#category').change(function(){
		if($('#category').val() != 'all') {
			var cutare;
			$('#brand_search').load('http://www.autoprim.ro/brands/ajax_get_brands_by_category/'+$('#category').val()+'/option/'+locales_id+'/false/brand_sear/brand');
			
			// for advanced search for to get the attributes:
			//alert(cutare);
			if(document.getElementById('advancedSearchForm'))
				$('#advancedSearchForm #attributes_container').load('http://www.autoprim.ro/posts/ajax_search_get_attributes_by_category/'+locales_id+'/'+$(this).val()+'/');
		} else {
			$('#brand_search').html('<select name="brand" id="brand_sear" onchange="brand_change();"><option value="all">---------- '+lang[locales_id]['all']+' ----------</option></select>');
			$('#model_search').html('<select name="model" id="model_sear" ><option value="all">---------- '+lang[locales_id]['all']+' ----------</option></select>');
		}
		
	});
	
	$('#brand_search').change(function(){
		
		if($('#brand_sear').val() != 'all') {
			$('#model_search').load('http://www.autoprim.ro/brands/ajax_get_models_by_brand_category/'+$('#brand_sear').val()+'/'+$('#category').val()+'/option/'+locales_id+'/model_sear/brand')
			//alert($(this).val());
		} else {
			$('#model_search').html('<select name="model" id="model_sear" ><option value="all">---------- '+lang[locales_id]['all']+' ----------</option></select>');
			
		}
		//alert($('#model_search').html());
	});
	
	
}

$(function(){
	$('.tabPane').tabs({fxFade: true,tabStruct: 'div>div',fxSpeed: 'fast',selectedClass: 'active',fxAutoFixHeight: true});
	
	initSearchForm();
});

// Tabs - hide tabs before initialization to avoid flash of content
// Add styles via JavaScript for graceful degradation...
document.write('<style type="text/css" media="projection, screen">.pane { display: none; }</style>');

function brand_change() {
if($('#brand_sear').val() != 'all') {
			$('#model_search').load('http://www.autoprim.ro/brands/ajax_get_models_by_brand_category/'+$('#brand_sear').val()+'/'+$('#category').val()+'/option/'+locales_id+'/model_sear/brand')
			
		} else {
			$('#model_search').html('<select name="model" id="model_sear" ><option value="all">---------- '+lang[locales_id]['all']+' ----------</option></select>');
			
		}
		
}

	/*function imageSizeWidth(id)
	{
		//var img = ;
		return img;
	}
	function imageSizeHeight(id)
	{
		//var img = document.getElementById(id).offsetHeight;
		return img;
	}*/
	function gatPadding()
	{
		var i=0;
		for(;;)
		{
			var id = 'img_'+i;
			var id_div = 'div_'+i;
			if(!document.getElementById(id))
				break;
				//alert(typeof(id));
			
			var width = document.getElementById(id).offsetWidth;/*imageSizeWidth(id)*/
			var height = document.getElementById(id).offsetHeight;//imageSizeHeight(id);
			if(width == 135 && height<125)
			{
				
				var rest = 125-height;
				var value = (rest/2);
				value = value +2;
				document.getElementById(id_div).style.padding = value+"px 2px";
			}
			if(width < 135 && height==125)
			{
				
				var rest = 135-width;
				var value = (rest/2);
				value = value +2;
				document.getElementById(id_div).style.padding = "2px "+value+"px";
				
			}
			if(width < 135 && height<125)
			{
				
				var rest = 135-width;
				var value = (rest/2);
				value = value +2;
				var rest = 125-height;
				var value2 = (rest/2);
				value2 = value2 +2;
				document.getElementById(id_div).style.padding = value2+"px "+value+"px";
				
			}
			
			//alert(width+' '+height);
			i++;
			
		}
	}
	
	