$(document).ready(function(){
	
	var s_state=getCookie('adv_search_menu');
	if (s_state==1){
	$("#adv_search").slideDown("slow");	
		}
    
    $("#adv_btn").click(function () {
	var s_state=getCookie('adv_search_menu');
		if (s_state==0){
		$("#adv_search").slideDown("slow");
		setCookie('adv_search_menu',1,100);
			}
		else{
		$("#adv_search").slideUp("slow");	
		setCookie('adv_search_menu',0,100);
			}
        });
	
	$("#mostviewed").click(function(){
		document.getElementById('latest').style.background="url(images/updates_btn_back.png)";
		document.getElementById('mostviewed').style.background="#ABABAB";
		$("#ucontainer").fadeOut("slow",function(){
							 	stepcarousel.stepTo('ucontainer2', 1);
								$("#ucontainer2").fadeIn("fast");			 
											 });
		});
		
	$("#latest").click(function(){
		document.getElementById('mostviewed').style.background="url(images/updates_btn_back.png)";
		document.getElementById('latest').style.background="#ABABAB";
		$("#ucontainer2").fadeOut("slow",function(){
							 	stepcarousel.stepTo('ucontainer', 1);
								$("#ucontainer").fadeIn("fast");			 
											 });
		});
		
	$("#make_search").change(function(){
		resetList();
		var parent_id=document.getElementById('make_search').value;
		if (parent_id=='any'){
			resetList();
			}
		else{
		jQuery.post('ajax/getMakes.php',{p_id:parent_id},function(data){
				var count =0;
				while (count<data.length){
					var d =document.createElement("option");
					d.setAttribute("value",data[count].id);
					d.innerHTML=data[count].name;
					document.getElementById("model").appendChild(d);
					count+=1;
					}
			},"json");
			}
		});
	

function resetList(){
document.getElementById("model").options.length=0;
var d =document.createElement("option");
d.setAttribute("name",'model');
d.setAttribute("value", 'any');
d.innerHTML="Any";
document.getElementById("model").appendChild(d);
}

function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}
function getUpdates(type){
	var getType = type;
	if (type=='mostviewed'){
	document.getElementById('latest').style.background="url(images/updates_btn_back.png)";
	document.getElementById('mostviewed').style.background="";
	$("#ucontainer").fadeOut("slow",function(){
							 	stepcarousel.stepTo('ucontainer2', 1);
								$("#ucontainer2").fadeIn("fast");			 
											 });
	}
	if (type=='latest'){
	document.getElementById('latest').style.background="";
	document.getElementById('mostviewed').style.background="url(images/updates_btn_back.png)";
	$("#ucontainer2").fadeOut("slow",function(){
							 	stepcarousel.stepTo('ucontainer', 1);
								$("#ucontainer").fadeIn("fast");			 
											 });
		}
		
	}
	
	
  });

function viewImg(id){
	var img_id='img_'+id;	
	var div_id='div_'+id;
	var pic = $('#'+div_id);
	var div_h = pic.height();
	$("#img_container").animate({opacity:0},300	)
		.animate( { height:div_h },300,function(){
						document.getElementById('img_container').innerHTML=document.getElementById(div_id).innerHTML;
						$("#img_container").animate( { height:div_h },300);
						$("#img_container").animate( { opacity:1 },300);
						});
											
	}




