﻿$(function() {

    var language_code = GetLanguageCode();
    var province_code = GetProvinceCode();

    if (language_code == 'en') {
        $('#menu_showroom').css('width', '94px');
        $('#menu_shoppingtools').css('width', '144px');
        $('#menu_so').css('width', '136px');
        $('#menu_dealer').css('width', '130px');
        $('#menu_about').css('width', '100px');
        $('#menu_kiaowners').css('width', '116px');
        //$('.menu_top_title a').css('padding', '0 18px');
        // pre-set cpo and fleet text
        $('#menuitem_cpo a').text('Certified Pre-Owned');
        $('#menuitem_fleet a').text('Fleet');
        $('#menuitem_concept a').text('Concept Vehicles');
      
    }
    else {
        $('#menu_showroom').css('width', '86px');
        $('#menu_shoppingtools').css('width', '100px');
        $('#menu_so').css('width', '150px');
        $('#menu_dealer').css('width', '140px');
        $('#menu_about').css('width', '128px');
        $('#menu_kiaowners').css('width', '114px');
        //$('.menu_top_title a').css('padding', '0 13px');
        $('#menuitem_cpo a').text('Véhicules certifiés');
        $('#menuitem_fleet a').text('Parcs automobiles');
        $('#menuitem_concept a').text('Véhicules Concept');
       
    }

    $('#menu_showroom_title a').css('cursor', 'default');
    $('#menu_shoppingtools_title a').css('cursor', 'default');

    $('#menu_showroom').hover(
       function() {
           $('#menu_showroom_container').show();
           $('.nav_item_hover').removeClass('nav_item_hover');
           $('#menu_showroom_right').hide();
       },
       function() {
           $('#menu_showroom_container').hide();
           $('#menu_showroom_right').hide();
       }
       );
    $('#menu_cpo').hover(function() { $('#menu_cpo_container').show(); }, function() { $('#menu_cpo_container').hide(); });
    $('#menu_shoppingtools').hover(function() { $('#menu_shoppingtools_container').show(); }, function() { $('#menu_shoppingtools_container').hide(); });
    $('#menu_kiaowners').hover(function() { $('#menu_kiaowners_container').show(); }, function() { $('#menu_kiaowners_container').hide(); });
    $('#menu_about').hover(function() { $('#menu_about_container').show(); }, function() { $('#menu_about_container').hide(); });
    $('#menu_so').hover(function() { $('#menu_so_container').show(); }, function() { $('#menu_so_container').hide(); });
    var model_title_type = '';

    if (province_code == 'AB' || province_code == 'BC' || province_code == 'QC') {
        model_title_type = '_dnd';
    }

    $('.nav_item_line').each(function(i) {
        $(this).hover(
         function() {
             $('.nav_item_line').removeClass('nav_item_hover');
             $(this).addClass('nav_item_hover');
             $('#menu_showroom_right').show();

             // populate links
             var model = $(this).find('a').text();
             if (model == 'Forte Koup') model = 'ForteKoup';
             if (model == 'Optima Hybrid') model = 'optimahybrid';
             if (model == 'Optima Hybride') model = 'optimahybrid';
             //alert(model);
            
             if (model.indexOf("portes") !=-1) 
             {                       
                model = 'Rio 5-door';
               
             }
             
              if (model.indexOf("door") !=-1) 
             {                       
                model = 'Rio 5-door';
                
             }             
             
             var prefixed_path = '/content/Vehicles/' + model + '/mainmenu/' + model;
             $('#model_top img').attr('src', prefixed_path + '_title_msrp' + model_title_type + '_' + language_code + '.png');
             $('#model_img img').attr('src', prefixed_path + '.png');
             $('#learn_more a').attr('href', '/pages/showroom/Overview.aspx?model=' + model);
             $('#build_price a').attr('href', '/pages/pricing/PriceKia.aspx?model=' + model);
             $('#build_price').show();
             $('#search_inventory').hide();
         },
         null);
    });
    $('#menuitem_sorento').hover(
      function() {
          $('.nav_item_line').removeClass('nav_item_hover');
          $(this).addClass('nav_item_hover');
          $('#menu_showroom_right').show();
          $('#build_price').hide();
          $('#search_inventory').hide();
          if (language_code == 'fr') {
              $('#menuitem_sorento a').attr('href', 'http://www.sorento2011.ca/French/main.html');
              $('#learn_more a').attr('href', 'http://www.sorento2011.ca/French/main.html');
          }
          else {
              $('#menuitem_sorento a').attr('href', 'http://www.2011sorento.ca/English/main.html');
              $('#learn_more a').attr('href', 'http://www.2011sorento.ca/English/main.html');
          }
          $('#menuitem_sorento a').attr('target', '_blank');
          $('#learn_more a').attr('target', '_blank');
      }, null);
    $('#menuitem_cpo').hover(
      function() {
          $('.nav_item_line').removeClass('nav_item_hover');
          $(this).addClass('nav_item_hover');
          $('#menu_showroom_right').hide();

          // populate links
          //$('#model_top img').attr('src', '/content/cpo/mainmenu/CPO_title_' + language_code + '.png');
          //$('#model_img img').attr('src', '/content/cpo/mainmenu/CPO.png');
          //$('#learn_more a').attr('href', '/pages/cpo/Overview.aspx');
          //$('#build_price').hide();
          //$('#search_inventory').hide();
          //$('#search_inventory').show();
          //$('#search_inventory a').attr('href', '/pages/cpo/FindCPOVehicle.aspx');
      }, null);
    $('#menuitem_fleet').hover(
      function() {
          $('.nav_item_line').removeClass('nav_item_hover');
          $(this).addClass('nav_item_hover');
          $('#menu_showroom_right').hide();

          // populate links
          //$('#model_top img').attr('src', '/content/fleet/mainmenu/Fleet_title_' + language_code + '.png');
          //$('#model_img img').attr('src', '/content/fleet/mainmenu/Fleet.png');
          //$('#learn_more a').attr('href', '#');
          //$('#build_price').hide();
          //$('#search_inventory').hide();
      }, null);

    $('#menuitem_concept').hover(
      function() {
          $('.nav_item_line').removeClass('nav_item_hover');
          $(this).addClass('nav_item_hover');
          $('#menu_showroom_right').hide();
      }, null);

    $('.choice_item').each(function(i) {
        $(this).hover(function() { $('.choice_item').removeClass('choice_item_hover'); $(this).addClass('choice_item_hover'); }, null);
    });


    $('.infiniteCarousel').infiniteCarousel();

    // debug

});

function ChangLanguage() {
    //Text_langLinkID
    var vLangLinkID = document.getElementById("Text_langLinkID").value;
    var vLangValueID = document.getElementById("Text_langValueID").value;
    var vEleLangLink = document.getElementById(vLangLinkID);
    var vEleLangValue = document.getElementById(vLangValueID);

    if (vEleLangLink.innerHTML == "English") {
        vEleLangLink.innerHTML = "Français";
        vEleLangValue.value = "0";
    }
    else {
        vEleLangLink.innerHTML = "English";
        vEleLangValue.value = "1";
    }
}
function GetLanguageCode() {
    //   if (getQueryStringByName('kr') == '1') {
    //      return 'kr';
    //   }

    var vLangLinkID = document.getElementById("Text_langLinkID").value;
    var vEleLangLink = document.getElementById(vLangLinkID);

    if (vEleLangLink.innerHTML == "English") {
        return "fr";
    }
    return "en";
}
function GetProvinceCode() {
    return $('.top_province option:selected').text();
}

function getQueryStringByName(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.href);
    if (results == null)
        return "";
    else
        return results[1];
}

