(function($){
/////////////////////////////////////
$(document).ready(function(){
////////////////////////////right-parts
$('.most-popular-block ul li').each(function(i){
        $(this).mouseover(function(){
                $(this).addClass('hover').siblings().removeClass('hover');
                $('.most-popular-block .bottom-block .bottom').hide().eq(i).show();
                var index=$(this).index();
                if(i==index){$('.most-popular-block .top').css("background-position","left -"+index*22+"px");}
        });
});
///////
$("#article-video-block .play").hover(function(){$(".btn-video-start",this).show();},function(){$(".btn-video-start",this).hide();});
///////
var _sel_make_ctrl=0;
var _sel_model_ctrl=0;
var _sel_morestreet_ctrl=0;
var _sel_moresport_ctrl=0;
var _sel_moretouring_ctrl=0;
var _sel_moremotocross_ctrl=0;
$("#sel-make-block").hover(function(){_sel_make_ctrl=1;},function(){_sel_make_ctrl=0;});
$("#sel-model-block").hover(function(){_sel_model_ctrl=1;},function(){_sel_model_ctrl=0;});
$("#sel-morestreet-block").hover(function(){_sel_morestreet_ctrl=1;},function(){_sel_morestreet_ctrl=0;});
$("#sel-moresport-block").hover(function(){_sel_moresport_ctrl=1;},function(){_sel_moresport_ctrl=0;});
$("#sel-moretouring-block").hover(function(){_sel_moretouring_ctrl=1;},function(){_sel_moretouring_ctrl=0;});
$("#sel-moremotocross-block").hover(function(){_sel_moremotocross_ctrl=1;},function(){_sel_moremotocross_ctrl=0;});
$(document).click(function(){
	if(_sel_make_ctrl==0) $('.right-buying-guide-block .make-selection-popup').slideUp('slow');
	if(_sel_model_ctrl==0) $('.right-buying-guide-block .model-selection-popup').slideUp('slow');
	if(_sel_morestreet_ctrl==0) $('.right-buying-guide-block .morestreet-selection-popup').slideUp('slow');
	if(_sel_moresport_ctrl==0) $('.right-buying-guide-block .moresport-selection-popup').slideUp('slow');
	if(_sel_moretouring_ctrl==0) $('.right-buying-guide-block .moretouring-selection-popup').slideUp('slow');
	if(_sel_moremotocross_ctrl==0) $('.right-buying-guide-block .moremotocross-selection-popup').slideUp('slow');
});
///////
$('.right-buying-guide-block .make-selection').click(function(){
        $popup=$('.right-buying-guide-block .make-selection-popup');
        $popupline=$('.right-buying-guide-block .make-selection-popup ul li a');
        if($popup.is(':hidden')){
                $popup.slideDown('slow');
                $popupline.each(function(){
                       $(this).click(function(){
                                $('.right-buying-guide-block .make-selection').text($(this).text());
                                $('.right-buying-guide-block .model-selection').css("color","#333")
                                $popup.hide();
                                $('.right-buying-guide-block .model-selection').text("MODEL");   ////to be modify
                                return false;
                       });
                });
        }else{ $popup.slideUp('slow'); };
});
///////
$('.right-buying-guide-block .model-selection').click(function(){
        if($('.right-buying-guide-block .make-selection').text()=="MAKE") return false;       ////to be modify
        $popupa=$('.right-buying-guide-block .model-selection-popup');
        $popuplinea=$('.right-buying-guide-block .model-selection-popup ul li a');
        if($popupa.is(':hidden')){
                $popupa.slideDown('slow');
                $popuplinea.each(function(){
                        $(this).click(function(){
                                $('.right-buying-guide-block .model-selection').text($(this).text());
                                $popupa.hide();
                                return false;
                        });
                });
        }else{ $popupa.slideUp('slow'); };
});
///////
function popup_ctrl_list($btn_click_cause,$popup_list){
        $btn_click_cause.click(function(){
                if($popup_list.is(':hidden')){
                        $popup_list.slideDown('slow');
                        $("ul li a",$popup_list[0]).each(function(){
                                $(this).click(function(){
                                        $btn_click_cause.text($(this).text());
                                        $popup_list.hide();
                                        return false;
                                });
                        });
                }else{ $popup_list.slideUp('slow'); };
        });
}
var $morestreet_btn=$('.right-buying-guide-block .morestreet-selection');
var $morestreet_popup=$('.right-buying-guide-block .morestreet-selection-popup');
popup_ctrl_list($morestreet_btn,$morestreet_popup);
var $moresport_btn=$('.right-buying-guide-block .moresport-selection');
var $moresport_popup=$('.right-buying-guide-block .moresport-selection-popup');
popup_ctrl_list($moresport_btn,$moresport_popup);
var $moretouring_btn=$('.right-buying-guide-block .moretouring-selection');
var $moretouring_popup=$('.right-buying-guide-block .moretouring-selection-popup');
popup_ctrl_list($moretouring_btn,$moretouring_popup);
var $moremotocross_btn=$('.right-buying-guide-block .moremotocross-selection');
var $moremotocross_popup=$('.right-buying-guide-block .moremotocross-selection-popup');
popup_ctrl_list($moremotocross_btn,$moremotocross_popup);
////////////////////////////menu
/*
$('#menu .menu-list li').each(function(){
        $(this).click(function(){
                $(this).addClass("viewing").siblings().removeClass("viewing");
        });
});
*/
function input_btn_click_blur($input,$btn,$tipinfo){
        $input.blur(function(){ if($(this).val()=="") $(this).val(this.defaultValue); });
        $input.click(function(){ if($(this).val()==this.defaultValue) $(this).val(""); });
        $btn.click(function(){
                if($input.val()==$input[0].defaultValue){ alert($tipinfo); }
		else window.location.href="/content/search?SearchText="+$input.val();
        });
}
var $inputab=$("#top-menu-search-input");
var $btnab=$("#btn-top-menu-search");
var $tipinfoab="Please input the search string!";
input_btn_click_blur($inputab,$btnab,$tipinfoab);
$inputab.keydown(function(event){
			if(event.keyCode == '13')
	 			window.location.href="/content/search?SearchText="+$(this).val();
		});
////////////////////////////search-block
var $inputbc=$("#input-search-block-top");
var $btnbc=$("#btn-search-block-top");
var $tipinfobc="Please input the search string!";
$inputbc.keydown(function(event){
			if(event.keyCode == '13')
	 			window.location.href="/content/search?SearchText="+$(this).val();
		});

input_btn_click_blur($inputbc,$btnbc,$tipinfobc);
///////////////////////////article
$('.article #make-selection .close').click(function(){
        $('.article #make-selection').slideUp(600);
        return false;
});
$('.article #model-selection .close').click(function(){
        $('.article #model-selection').slideUp(600);
        return false;
});
$('.article .content .select-a-make').click(function(){
        var $popup=$('#make-selection');
        if($popup.is(':hidden')){
                $popup.slideDown(600);
                return false;
        }else{
                $popup.slideUp(600);
                return false;
        }
});
$('.article #make-selection .list ul li a').click(function(){
        $('.article .content .select-a-make').text($(this).text());
        $('.article .content .select-a-make').append(" &#187;");
        if($('.buyers-guide-block .select-a-make').text()!="Select a Make »"){
                var $related=$('.article .content .select-a-model');
                $related.text("Select a Model »");
                $related.css("color","#000");
        }
        $('.article #make-selection').slideUp(600);
        return false;
});
$('.article .content .select-a-model').click(function(){
        if($('.article .content .select-a-make').text()=="Select a Make »")return false;
        var $popupc=$('.article #model-selection');
        if($popupc.is(':hidden')){
                $popupc.slideDown(600);
                return false;
        }else{
                $popupc.slideUp(600);
                return false;
        }
});
$('.article #model-selection .list ul li a').click(function(){
        $('.article .content .select-a-model').text($(this).text());
        $('.article .content .select-a-model').append(" &#187;");
        $('.article #model-selection').slideUp(600);
        return false;
});
////////////////////////////buyers-guide
$('#make-selection .close').click(function(){
        $('#make-selection').hide(600);
        return false;
});
$('#model-selection .close').click(function(){
        $('#model-selection').hide(600);
        return false;
});
$('.buyers-guide-block .make').click(function(){
        $('#make-selection').show(600);
        return false;
});
$('#make-selection .list ul li a').click(function(){
        $('.buyers-guide-block .make').text($(this).text());
        $('.buyers-guide-block .make').append(" &#187;");
        if($('.buyers-guide-block .make').text()!="Select a Make &#187;"){
                $('.buyers-guide-block .model').css("color","#000000");
        }
        $('#make-selection').hide(600);
        $('.buyers-guide-block .model').click(function(){
                $('#model-selection').show(600);
                return false;
        });
        return false;
});
$('#model-selection .list ul li a').click(function(){
        $('.buyers-guide-block .model').text($(this).text());
        $('.buyers-guide-block .model').append(" &#187;");
        $('#model-selection').hide(600);
        return false;
});
////////////////////////////
});
})(jQuery);
