/* Author: 

*/
$.fn.selectMenu = function() {
		var strVal=$(" > div",this);
		var list=$(" > ul",this);
		$(" > div",this).click(function(){
			$(list).slideDown();
		});
		$("li",this).click(function(){
			$(strVal).text($(this).text());
			$(list).slideUp("fast");
		});
	}
	$.fn.fancyRadio = function() {
	this.click(function(){
		$(this).siblings().removeClass("checked");
		$(this).addClass("checked");
		$('input:radio',this).attr('checked', true)
		var el=$(this);
	});
}
	$(document).ready(function(){
            $("select").detectmouseoverdisabled();
            
            
		$(".article-scroller, .featured-slider").scrollable();
		$("#news-tabs ul.tabs").tabs("#news-tabs .tab-container");
		$("#featured-tabs ul.tabs").tabs("#featured-tabs .tab-container");
		$("#car-details-tab ul.tabs").tabs("#car-details-tab .tab-container",{
			onClick:function(event, tabIndex){
				$("#car-details-tab ul.tabs li span").remove();
				$("#car-details-tab ul.tabs li:eq("+tabIndex+")").append("<span></span>");
			}
		});
		$(".car-table tr:odd , .bike-table tr:odd").addClass("odd");/*
		$(".car-table tr td:first-child").addClass("uppercase");*/
		$(".car-table tr td:first-child,.bike-table tr td:first-child").addClass("uppercase-comp");
		$(".select-menu").selectMenu();
		$(".check-list li").fancyRadio();
		
		$("#option1").click(function(){
		$(this).next().slideDown("fast");
	    });
	    $("#option2").click(function(){
		$(this).next().slideDown("fast");
	    });
	    $("#option3").click(function(){
		$(this).next().slideDown("fast");
	    });	
	    $("#option4").click(function(){
		$(this).next().slideDown("fast");
	    });	
	    $("#filter-category-vehicle li").live('click',function(){
		$("#option1").text($(this).text());
		$(this).parent().slideUp("fast");
	    });
	
	    $("#filter-category-type li").live('click',function(){
		$("#option2").text($(this).text());
		$(this).parent().slideUp("fast");
	    });
	
	    $("#filter-category-variant li").live('click',function(){
		$("#option3").text($(this).text());
		$(this).parent().slideUp("fast");
	    });
	
	    $("#filter-category-price li").live('click',function(){
		$("#option4").text($(this).text());
		$(this).parent().slideUp("fast");
		});
		
		$('#filter-category-compare').click(function(){
		$('.compare-pop').fadeIn("normal");
	});
        /*,
	function(){
	});
	$('#compare-block').hover(function(){
		
	},
	function(){$('.compare-pop').fadeOut("fast");
	});
	*/
	
	 $(".accordion-terms h3:first").addClass("active");
       $(".accordion-terms div.info:not(:first)").hide();

       $(".accordion-terms h3").click(function(){
               $(this).next("div.info").slideToggle("");
               //.siblings("div.info:visible").slideUp("");
               $(this).toggleClass("active");
               $(this).siblings("h3").removeClass("active");
       });
	
	/*$(".rate-block a.close-comp").click(function(){
    $(".rate-block").fadeOut("normal");
	});*/
		
	
	//$(".royal-acordian-container h3:first").addClass('rd');		 
	$('.press-rel-content h3, .press-rel-content-lounge h3,.royal-acordian-container h3').click(function(){
		var getDiv=$(this).next(".press-content,.press-content-lounge,.royal-content");
		//$(getDiv).siblings('.press-content,.press-content-lounge,.royal-content').slideUp()
		$(getDiv).slideToggle();
		$(this).toggleClass('rd');
		//$(this).siblings('h3').removeClass('rd');		
	});

	});



function elementSupportsAttribute(element,attribute) {
	var test = document.createElement(element);
	if (attribute in test) {
		return true;
	} else {
		return false;
	}
}
$.fn.initVal = function(value) {
	$(this).val(value);
	$(this).focus(function(){
		if($(this).val()==value){$(this).val('')}
	});
	$(this).blur(function(){
		if($(this).val()==''){$(this).val(value)}
	});
}

$.fn.initCheck = function(value) {if($(this).val()==value){$(this).val('')}}

if (!elementSupportsAttribute('input','placeholder')) {
	$("#search-field").initVal("ENTER KEYWORD");
	$("#keyword-results").initVal("ENTER KEYWORD");
}

$.fn.selectMenu = function() {
		var strVal=$(" > div",this);
		var list=$(" > ul",this);
		$(" > div",this).click(function(){
			$(list).slideDown();
		});
		$("li",this).click(function(){
			$(strVal).text($(this).text());
			$(list).slideUp("fast");
		});
	}
        
$(document).ready(function(){
	$("#show-scrollable").scrollable({vertical:true, speed:"slow"}).autoscroll({autoplay: true, interval:3100});
            // $("#show-scrollable").scrollable({vertical:true, speed:"slow"});
		var showScroll;
                showScroll = $("#show-scrollable").data("scrollable");
                if(showScroll)
                showScroll.onBeforeSeek(function(event,index)
                {
                   //showScroll.begin();
                   //return false;
                   
                   var current = $("#show-scrollable ul li").index($(".current"));
                   //$("#home").html(current+" ="+this.getSize());
                   {
                       if(current==(this.getSize()-1))
                           this.seekTo(0,300,true);
                   }
                  
                   //$("#home").html(showScroll.getConf());
                   if (current >= this.getSize() - 3)
                       {
                            if (index > this.getIndex()) {

                                return false;
                            }
                            
                       }
                        

                });
                if(showScroll)
                showScroll.onSeek(function(event,index)
                {
                  if (this.getIndex() >= this.getSize() - 3)
                  $("a.next").addClass("disabled");
                   
                });
                $("#show-scrollable").tabs(".home-slides-item", {
			// enable "cross-fading" effect
			effect: 'fade',
			tabs:"li",
			fadeOutSpeed: "slow",
			initialIndex:0,
			rotate: true		
			// use the slideshow plugin. It accepts its own configuration
		//});
		}).slideshow({interval:3100, autoplay:true});
                
		$(".article-scroller, .featured-slider, .gallery-slider").scrollable();
		$("#news-tabs ul.tabs").tabs("#news-tabs .tab-container");
		$("#featured-tabs ul.tabs").tabs("#featured-tabs .tab-container");
		$("#gallery-tab ul.tabs").tabs("#gallery-tab .tab-container",{
			onClick:function(event, tabIndex){
				$("#gallery-tab ul.tabs li span").remove();
				$("#gallery-tab ul.tabs li:eq("+tabIndex+")").append("<span></span>");
			}
		});
		$(".car-table tr:odd,.bike-table tr:odd").addClass("odd");
		$(".car-table tr td:first-child,.bike-table tr td:first-child").addClass("uppercase");
		$(".select-menu").selectMenu();
		$("a[rel='picture']").colorbox({
			onOpen:function(){$("#colorbox").addClass("gallery-box")},
			onComplete:function(){$("#cboxTitle").css("width",$("cboxContent img").width())}
		});
		$('#issue-scrollbar').tinyscrollbar();
		var oScrollbar = $('#issue-scrollbar');
		oScrollbar.tinyscrollbar();
		//some operation that changes the viewport content...
		$("#latest-issue a").colorbox({inline:true, href:"#issue-box", width:"384px",
			onComplete:function(){oScrollbar.tinyscrollbar_update();}						  
		});
		
		var waitCaptcha = true;
                var postedDirect = false;
                var comment_validate = $("#comment_form").validate({
		rules: {
			comment_msg: "required",
			comment_name: "required",
			comment_captcha: {
                            //remote: base_url+"/verify_captcha",
                            required: true
                            
                            },
			comment_email_id: {
				required: true,
				email: true
			}
		},
		messages: {
			comment_msg: "Please enter a message",
			comment_name: "Please enter your name",
			comment_captcha: {
				required: "Enter a captcha"
                            },
			comment_email_id: "Please enter a valid email address"
			
			
		},
                errorContainer: $("#error_container"),
		errorLabelContainer: $("ol", $("#error_container")),
		wrapper: 'li',
		meta: "validate"
	});
       
       
       function postComment()
       {
                   
                    if(valStatus)
                        {
                            
                            
                        }
       }
                
                $("#post_comment").click(function(){
                    
                    
                    $("#comment_msg").initCheck("comment");
                    $("#comment_name").initCheck("name");
                    $("#comment_city").initCheck("city"); 
                    $("#comment_email_id").initCheck("email id"); 
                    $("#comment_captcha").initCheck("enter here"); 
                    
                    
                    var valStatus = comment_validate.form();
                    if(valStatus)
                        {
                            
                            $.get(base_url+"/verify_captcha",{comment_captcha:$("#comment_captcha").val()},function(data){
                                if(data==true)
                                    {
                                        var msg = $("#comment_msg").val();
                                        var name= $("#comment_name").val();
                                        var city= $("#comment_city").val();
                                        var currentTime = new Date();
                                        var year = currentTime.getFullYear();
                                        currentTime.toLocaleFormat("YYYY-MM-DDThh:mmTZD");


                                        $.post(base_url+"/save_comment",$("#comment_form").serialize(),function(data){
                                            if(parseInt(data))
                                                {
                                                    $(".show-comt-list").prepend("<li id=\"comment_li_"+data+"\">\n\
                <div class=\"comment-wrap\"><div class=\"comment-padder\">\n\
            <figure><img height=\"66\" width=\"67\" src=\""+base_theme+"/images/thumb-overd.gif\" alt=\"\">\n\
            </figure><div class=\"comments-block\"><h4>"+name+", <span class=\"city\">"+city+"</span></h4>\n\
            <time datetime=\""+currentTime+"\" class=\"prettydate\" title=\""+currentTime+"\">"+currentTime+"</time><p>"+msg+"</p></div><div class=\"like-ctn\"> \n\
            <a href=\"javascript:void(0)\" onclick=\"javascript:report_comment("+data+")\" class=\"report\">report</a> <a href=\"javascript:void(0)\" onclick=\"javascript:like_comment("+data+")\" class=\"like\">+like</a> <a href=\"javascript:void(0)\" onclick=\"javascript:reply_comment("+data+")\" class=\"replay\">\n\
            replay</a> </div></div></div></li>");
                                            $(".prettydate").prettyDate();
                                            $("#comment_msg").initVal("comment");
                                            $("#comment_name").initVal("name");
                                            $("#comment_city").initVal("city"); 
                                            $("#comment_email_id").initVal("email id"); 
                                            $("#comment_captcha").initVal("enter here"); 
                                            }
                                        });
                                    }
                                    else
                                        {
                                             
                                            if(!$("#error_container").is(":visible"))
                                                {
                                                    $("ol", $("#error_container")).html("");
                                                    $("#error_container").show();
                                                    $("ol", $("#error_container")).show();
                                                }
                                            if($("ol", $("#error_container")).length<1)
                                                {
                                                    $("#error_container").append("<ol></ol>");
                                                }
                                                
                                                if(parseInt($("[for*='comment_captcha']", $("#error_container")).length)==0)
                                                {
                                                   
                                                    
                                                    $("ol", $("#error_container")).html($("ol", $("#error_container")).html()+"<li><label class=\"error\" for=\"comment_captcha\" generated=\"true\" style=\"display: block;\">Captcha is not valid</label></li>");
                                                }
                                                //$("ol", $("#error_container")).add("li").add("label").addClass("error").attr({"for":"comment_captcha","generated":"true","style":"display: block;"}).html("Captcha is not valid");
                                        }
                            });
                        }
                        else
                            {
                                $.get(base_url+"/verify_captcha",{comment_captcha:$("#comment_captcha").val()},function(data){
                                    if(data!=true)
                                        {
                                            if(!$("#error_container").is(":visible"))
                                                {
                                                    $("ol", $("#error_container")).html("");
                                                    $("#error_container").show();
                                                }
                                            if($("ol", $("#error_container")).length<1)
                                                {
                                                    $("#error_container").append("<ol></ol>");
                                                }
                                                
                                                if(parseInt($("[for*='comment_captcha']", $("#error_container")).length)==0)
                                                {
                                                    $("ol", $("#error_container")).append('<li><label class="error" for="comment_captcha" generated="true" style="display: block;">Captcha is not valid</label></li>');
                                                }
                                        }
                                });
                            }
                   
                });

$(".send_newsletter").colorbox({innerWidth:200});
$(".send_email").colorbox({innerWidth:200});
$("#email_submit, #newsletter_submit").live("click",function(){
	$.colorbox.resize()
});

 $.validator.addMethod("alpha", function(value, element) {
return this.optional(element) || value == value.match(/^[a-zA-Z]+$/);
},"Only Characters Allowed.");
});

function search_site(){
    var searchTerm = $.trim($("#search-field").val());
    if(searchTerm)
        {
            document.location.href = base_url+"/mysearch/"+searchTerm;
        }
        else
            {
                $("#search-field").focus();
            }
            return false;
}

function subscribe_newsletter()
{
    var newsletterVal = $("#newsletter_form").validate({
        rules:
        {
            name:{required:true,
        alpha:true    
        },
            email:{
                required:true,
                email:true
            }
        },
        messages:
            {
                name:{required:"Please enter your name",
                alpha:"Name should contain only alphabets"},
                email:"Please enter a valid email"
            },
            errorLabelContainer:$("#newsletter_error"),
            wrapper:"div"
    });
    $("#newsletter_name").initCheck("Name");
    $("#newsletter_email").initCheck("Email");
    if(newsletterVal.form())
        {
            $.post(base_url+"/save_newsletter", $("#newsletter_form").serialize(), function(data){
                $.fn.colorbox({html:"<div>"+data+"</div>", open:true});
            })
        }
}
function send_friend()
{
    var emailVal = $("#email_form").validate({
        rules:
        {
            mname:"required",
            memail:{
                required:true,
                email:true
            },
            fname:"required",
            femail:{
                required:true,
                email:true
            }
        },
        messages:
            {
                mname:"Please enter your name",
                memail:"Please enter your valid email",
                fname:"Please enter your friend's name",
                femail:"Please enter your friend's valid email"
            },
            errorLabelContainer:$("#email_error"),
            wrapper:"div"
    });
    $("#email_name").initCheck("Name");
    $("#email_email").initCheck("Email");
    $("#email_fname").initCheck("Name");
    $("#email_femail").initCheck("Email");
    if(emailVal.form())
        {
            $.post(base_url+"/send_friend", $("#email_form").serialize(), function(data){
                $.fn.colorbox({html:"<div>"+data+"</div>", open:true});
            })
        }
}
function like_comment(id)
{
    $.post(base_url+"/like_comment", {id:id}, function(data){
                $(".like",$("#comment_li_"+id)).remove();
                //$.fn.colorbox({html:"<div>"+data+"</div>", open:true});
            })
}
function report_comment(id)
{
    $.post(base_url+"/report_comment", {id:id}, function(data){
                $(".report",$("#comment_li_"+id)).remove();
                //$.fn.colorbox({html:"<div>"+data+"</div>", open:true});
            })
}
function reply_comment(id)
{
    $.get(base_url+"/reply_comment_form",{pid:id,nid:$("#nid").val()},function(data){
        $.fn.colorbox({html:"<div>"+data+"</div>", open:true});
        $("#reply_msg").initVal("comment");
      $("#reply_name").initVal("name");
      $("#reply_city").initVal("city"); 
      $("#reply_email_id").initVal("email id"); 
      $("#reply_captcha").initVal("enter here"); 
    });
}
function save_reply()
{
    var reply_validate = $("#reply_form").validate({
		rules: {
			comment_msg: "required",
			comment_name: "required",
			comment_captcha: {
                            remote: base_url+"/verify_captcha",
                                required: true
                            },
			comment_email_id: {
				required: true,
				email: true
			}
		},
		messages: {
			comment_msg: "Please enter a message",
			comment_name: "Please enter your name",
			comment_captcha: {
				required: "Enter a captcha",
				remote: "Captcha is not valid"
                            },
			comment_email_id: "Please enter a valid email address"
			
			
		},
                errorContainer: $("#reply_error_container"),
		errorLabelContainer: $("ol", $("#reply_error_container")),
		wrapper: 'li',
		meta: "validate"
	});
                    $("#comment_msg").initCheck("comment");
                    $("#reply_name").initCheck("name");
                    $("#reply_city").initCheck("city"); 
                    $("#reply_email_id").initCheck("email id"); 
                    $("#reply_captcha").initCheck("enter here"); 
                    if(reply_validate.form())
                        {
                            var msg = $("#reply_msg").val();
                            var name= $("#reply_name").val();
                            var city= $("#reply_city").val();
                            var currentTime = new Date();
                            var year = currentTime.getFullYear();
                            currentTime.toLocaleFormat("YYYY-MM-DDThh:mmTZD");
                            
                            
                            $.post(base_url+"/save_comment",$("#comment_form").serialize(),function(data){
                                if(parseInt(data))
                                    {
                                        $("#comment_li_"+id).prepend("<li id=\"comment_li_"+data+"\">\n\
    <div class=\"comment-wrap\"><div class=\"comment-padder\">\n\
<figure><img height=\"66\" width=\"67\" src=\""+base_theme+"/images/thumb-overd.gif\" alt=\"\">\n\
</figure><div class=\"comments-block\"><h4>"+name+", <span class=\"city\">"+city+"</span></h4>\n\
<time datetime=\""+currentTime+"\" class=\"prettydate\" title=\""+currentTime+"\">"+currentTime+"</time><p>"+msg+"</p></div><div class=\"like-ctn\"> \n\
<a href=\"javascript:void(0)\" onclick=\"javascript:report_comment("+data+")\" class=\"report\">report</a> <a href=\"javascript:void(0)\" onclick=\"javascript:like_comment("+data+")\" class=\"like\">+like</a> <a href=\"javascript:void(0)\" onclick=\"javascript:reply_comment("+data+")\" class=\"replay\">\n\
replay</a> </div></div></div></li>");
                                $(".prettydate").prettyDate();
                                }
                            });
                        }
}


$(document).ready(function(){
    
    $("#filter-category-vehicle ul li").live('click',function(){
      
      //var brand   = $(this).attr('value');
      $("#brand").val($(this).attr('value'));
      getType();
      getPrice();
      getVariants();
    });
    
    
    $("#filter-category-type ul li").live('click',function(){
      if($(this).attr('rel')!=0)
          {
              $("#type").val($(this).attr('rel'));
                getBrand();
                getPrice();
                getVariants();
          }
          else
              {
                  $("#filter-category-type div").html("Type");
              }
      
    });
    
    $("#filter-category-price ul li").live('click',function(){
        $("#price_range").val($(this).attr('rel'));
        getBrand();
        getType();
        getVariants();
    });
    
    $("#compare-block .check-list li").live('click',function(){
         $("input:radio",$(this)).attr('checked', 'true');
         refreshLists();
    });
    
    
    $("[name*=select_brand]").live('change',function(){
       var vehicle = $("[name=vehicle]:checked").val();
       var my_id    = $(this).attr("id").match(/\d+/);
       hideError();
      $.get(base_url+"/buyers_guide/"+vehicle+"/model/"+$(this).val(),{tag:"option"},function(data){
          $("#select_model_"+my_id).html("<option value=\"\">Select Model</option>"+data);
          $("#select_model_"+my_id).removeAttr('disabled');
          $("#select_variant_"+my_id).html("<option value=\"\">Select Version</option>");
      });
    });
    
    $("[name*=select_model]").live('change',function(){
       var vehicle = $("[name=vehicle]:checked").val();
       var my_id    = $(this).attr("id").match(/\d+/);
       hideError();
      $.get(base_url+"/buyers_guide/"+vehicle+"/variant/"+$(this).val(),{tag:"option"},function(data){
          $("#select_variant_"+my_id).html("<option value=\"\">Select Version</option>"+data);
          $("#select_variant_"+my_id).removeAttr("disabled");
      });
    });
    
    $("[name*=select_variant]").live('change',function(){
    hideError();
    });
    
    $("#compare-btn").live('click',function(){
        var seen = {};
        var totalVeh = 0;
        var vehicle = $("[name=vehicle]:checked").val();
        var error = false;
        $("[name*=select_variant]").each(function() {
            var val = $(this).val();
            var my_id    = $(this).attr("id").match(/\d+/);
            if(seen[val] && val!=0)
                {
                    //error
                    
                    showError("Please Select a different variant");
                    error = true;
                    return false;
                   
                }
                
                else if(val==0 && $("#select_brand_"+my_id).val()!=0)
                {
                    //error
                    showError("Please select a vehicle varient to compare");
                    error = true;
                    return false;
                }
                else if(val!=0)
                    {
                        totalVeh++;
                        seen[val] = true;
                    }
        });
        
        if(totalVeh<2 && error==false)
            {
                //error
                showError("Select at least two vehicles");
                error = true;
                return false;
            }
            if(!error)
                {
                    $("#compare_vehicle_form").attr("method","POST");
                    $("#compare_vehicle_form").attr("action",base_url+"/buyers_guide/compare_"+vehicle);
                    $("#compare_vehicle_form").submit();
                }
            
        
    });
    
    $(".close-comp").live('click',function(){
       var rel = $(this).attr("rel");
       $(this).parent().remove();
       $(".tab-container-compare table tr td:nth-child("+rel+")").remove();
       $(".tab-container-compare table").width($(".tab-container-compare table").width()-187);
       $(".compare-rate-block .rate-block").each(function(i,e){
           $('.close-comp',this).attr("rel",i+1);
       });
    });
    
    $("#filter-category-variant ul li").live('click',function(){
        var id = $(this).attr('rel');
        if(id!=0)
            {
                var vehicle = $("[name=vehicle]:checked").val();
                document.location.href = base_url+"/buyers_guide/"+vehicle+"/"+id;
            }
            else
                {
                    $("#filter-category-variant div").html("Vehicle");
                }
        
    });
var over_cmp=false;
$("#filter-category-compare").live("hover",function(){
    over_cmp=true;
    
});
$("#filter-category-compare").live("mouseout",function(){
    over_cmp=false;
    ;
});
$("#filter-category-compare *").live("mouseover",function(){
    over_cmp=true;
    
});
$("#filter-category-compare *").live("click",function(){
    over_cmp=true;
    $('#test').html("True");
});
$("*").click(function(e){
   $("#filter-category-price div, #filter-category-vehicle div, #filter-category-type div, #filter-category-variant div").each(function(){
       if(e.target.id!=$(this).attr("id"))
           {
               $("ul",$(this).parent()).hide();
           }
        
   });
   
  if(!over_cmp)
            {
                $("#compare-popup").hide();
            }
       
});

  $("#filter-category-price li, #filter-category-vehicle li, #filter-category-type li, #filter-category-variant li").live('hover',function(){
        $("#filter-category-price li, #filter-category-vehicle li, #filter-category-type li, #filter-category-variant li").removeClass('hover-bg').filter(this).addClass('hover-bg');
    });
    
    $("#filter-category-price li, #filter-category-vehicle li, #filter-category-type li, #filter-category-variant li").live('mouseout',function(){
            $(this).removeClass('hover-bg');
        });



})


function showError(msg)
{
    $("#compare_error").show();
    $("#compare_error").html(msg);
    //setTimeout(hideError,3000);
}
function hideError()
{
    $("#compare_error").hide();
    $("#compare_error").html(" ");
}



function setCompare(val,type)
{
    var vehicle = $("[name=vehicle]:checked").val();
    if(vehicle=="bike")
        var curComp = bike_compare_count + 1;
    else
        var curComp = car_compare_count + 1;
    if(curComp<=4)
        {
            switch(type)
                {
                    case "brand":
                    {
                        $("#select_brand_"+curComp).val(val);
                        $("#select_brand_"+curComp).trigger("change");
                    }
                    break;
                    case "model":
                        $("#select_model_"+curComp).val(val);
                        $("#select_model_"+curComp).trigger("change");
                        break;
                    case "variant":
                        $("#select_variant_"+curComp).val(val);
                        break;
                }
        }
    
}

function getBrand()
{
    var vehicle = $("[name=vehicle]:checked").val();
    $.get(base_url+"/buyers_guide/"+vehicle+"_brand",$("#compare_form").serialize(),function(data){
         $("#filter-category-vehicle ul").html(data);
         
    });
}
function getType()
{
    var vehicle = $("[name=vehicle]:checked").val();
    $.get(base_url+"/buyers_guide/"+vehicle+"_type",$("#compare_form").serialize(),function(data){
         $("#filter-category-type ul").html(data);
         
    });
    
}
function getPrice()
{
    var vehicle = $("[name=vehicle]:checked").val();
    $.get(base_url+"/buyers_guide/"+vehicle+"_price",$("#compare_form").serialize(),function(data){
         $("#filter-category-price ul").html(data);
         
    });
}


function getVariants()
{
    if(Boolean($("#brand").val().trim()))
        {
            var vehicle = $("[name=vehicle]:checked").val();
            $.get(base_url+"/buyers_guide/"+vehicle+"_list",$("#compare_form").serialize(),function(data){
                $("#filter-category-variant ul").html(data);
         
            });
        }
}
function getCompareBlock()
{
    var vehicle = $("[name=vehicle]:checked").val();
    $.get(base_url+"/buyers_guide/"+vehicle+"_compare_block",function(data){
         $("#compare-popup").html(data);
        if((typeof bikeValArr != 'undefined') && vehicle=="bike")
        {
            
            ReserveRow("bike",bikeValArr[0],bikeValArr[1],bikeValArr[2]);
        }
    if((typeof carValArr != 'undefined') && vehicle=="car")
        {
            
            ReserveRow("car",carValArr[0],carValArr[1],carValArr[2]);
        }
    });
    
}
function getModels()
{
    var brand =  $("#brand").val();
    var vehicle = $("[name=vehicle]:checked").val();
    var priceRange=$("#price_range").val();
    setCompare(brand,"brand")
      $.get(base_url+"/buyers_guide/"+vehicle+"/model/"+brand,{range:priceRange},function(data){
         $("#filter-category-type ul").html(data);
         if(data)
            $("#filter-category-type div").html("Type");
        else
            $("#filter-category-type div").html("No Model");
         $("#filter-category-variant ul").html("<li value=\"\">Please Select a Type first</li>");
         $("#filter-category-variant div").html("Variant");
      });
}
function refreshLists()
{
        $("#brand").val(" ");
         $("#type").val(" ");
         $("#price_range").val(" ");
         $("#filter-category-vehicle div").html("Brand");
         $("#filter-category-type div").html("Type");
         $("#filter-category-price div").html("Price Range");
         $("#filter-category-variant div").html("Vehicle");
         getBrand();
         getType();
        getPrice();
        getCompareBlock();
        $("#filter-category-variant ul").html("<li rel=\"\">Please Select a Brand first</li>");
}
function ReserveRow(type,brand,model,variant)
{
    var vehicle = $("[name=vehicle]:checked").val();
    if(type==vehicle)
        {
            $.ajaxSetup({async:false});
            setCompare(brand,"brand");
            setCompare(model,"model");
            setCompare(variant,"variant");
            $.ajaxSetup({async:true});
        }
    
}
function stackFull(vehicle)
{
    
    $("body").append("<div class=\"splash\"><div class=\"splash-bg\"></div><div class=\"splash-img\"><a class=\"splash-close\">Close</a><div class=\"upload-block\"><img alt=\"Overdrive\" src=\""+base_url+"/sites/all/themes/overdrive/images/others/"+vehicle+"-pop.jpg\"></div></div></div>");
    $(".splash").show();
    $(".splash-close").click(function(){
        $(".splash").remove();
    });
}
function add_compare(val,type)
{
  var vehicle = $("[name=vehicle]:checked").val();
    if(vehicle=="bike")
        var curComp = bike_compare_count + 1;
    else
        var curComp = car_compare_count + 1;
    if(curComp<=4)
        {  
            $.get(base_url+"/buyers_guide/"+type+"_add_compare/"+val,function(data){
                //$(".compare-btn-right").remove();
                $(".compare-btn-right img").attr("src",base_url+"/sites/all/themes/overdrive/images/others/"+vehicle+"_compare_red.jpg");
                var btn = $(".compare-btn-right a").html();
                $(".compare-btn-right a").remove();
                $(".compare-btn-right").html(btn);
                $("body").append(data);
                /*$("body").append("<div class=\"splash\"><div class=\"splash-bg\"></div><div class=\"splash-img\"><a class=\"splash-close\">Close</a><div class=\"upload-block\" style=\"color:#FFFFFF;font-size:24px;font-weight:bold;text-align:center;\">Added to compare list.</div></div></div>");
                $(".splash").show();
                $(".splash-close").click(function(){
                    $(".splash").remove();
                });*/
            });
        }else
            {
                
                stackFull(vehicle);
            }
}

function resetVehicle()
{

    var vehicle = $("[name=vehicle]:checked").val();
    var img = $("#resetImg").attr("src");
    $("#resetImg").attr("src",base_url+"/sites/all/themes/overdrive/images/loader.gif");
    $.get(base_url+"/buyers_guide/"+vehicle+"_reset",function(data){
         refreshLists();
         $("#resetImg").attr("src",img);
         if(vehicle=="bike")
             bike_compare_count = 0;
         else
             car_compare_count =0;
         
    });
    
    
    
}

