﻿var active_feature;

jQuery(function() {

    if (jQuery('.NewsRight').length > 0) {
        if (jQuery('.NewsRight ul li.active').length > 0) {

            var old_headline = 0;
            var current_headline = 0;
            var headline_count = jQuery(".NewsRight ul li").size();

            jQuery('.NewsLeft ul li.NewsHide').hide();

            setInterval(function() {
                current_headline = (old_headline + 1) % headline_count;
                jQuery(".NewsRight ul li:eq(" + old_headline + ")").removeClass('active');
                jQuery(".NewsRight ul li:eq(" + current_headline + ")").addClass('active');
                jQuery(".NewsLeft ul li:eq(" + old_headline + ")").hide().removeClass('NewsShow').addClass('NewsHide');
                jQuery(".NewsLeft ul li:eq(" + current_headline + ")").removeClass('NewsHide').addClass('NewsShow').fadeIn('slow')
                old_headline = current_headline;
            }, 7000);
        }
    }

    if (jQuery('.ChangeLanguage').length > 0) {

        jQuery('.ChangeLanguage a').click(function() {
            var a = jQuery('#LanguageSelector');
            if (a.is(':visible')) {
                a.css("visibility", "hidden");
            }
            else {
                a.css("visibility", "visible").hover(function() {
                }, function() {
                    jQuery(this).css("visibility", "hidden");
                });
            }
        });
    }

    if (jQuery('div.ProductFeature').length > 0) {

        jQuery('.TabbedNav ul').show();
        jQuery(".ProductInner p.hidden").removeClass("hidden");

        active_feature = extractFeature('fid');

        if (active_feature == '') {
            jQuery('#TabbedOverview').addClass('active');
            jQuery('#TabbedFeature').removeClass('active');
            jQuery('#ProductOverview').show();
            jQuery('#ProductFeatures').hide();
        } else {
            jQuery('#TabbedOverview').removeClass('active');
            jQuery('#TabbedFeature').addClass('active');
            jQuery('#ProductOverview').hide();
            jQuery('#ProductFeatures').show();
            jQuery('.ProductFeature').hide();
            jQuery('#' + active_feature).show();
            jQuery('#a' + active_feature).children('a').eq(0).hide();
            jQuery('#a' + active_feature).children('a').eq(1).show();

            window.location = '#f' + active_feature.substring(1, active_feature.length);            
        }

        jQuery('#TabbedOverview').click(function() {
            jQuery(this).addClass('active');
            jQuery('#TabbedFeature').removeClass('active');
            jQuery('#ProductOverview').show();
            jQuery('#ProductFeatures').hide();
        });

        jQuery('#TabbedFeature').click(function() {
            jQuery(this).addClass('active');
            jQuery('#TabbedOverview').removeClass('active');
            jQuery('#ProductOverview').hide();
            jQuery('#ProductFeatures').show();
            jQuery('.ProductFeature').hide();
        });
    }

    if (jQuery('#bookmark').length > 0) {

        var url = window.document.location;
        var title = window.document.title;
        var bookmark = jQuery('#bookmark');

        if (jQuery.browser.msie) {
            bookmark.children('a').click(function() {
                window.external.AddFavorite(url, title); return false;
            });
            bookmark.show();
        }

        if (jQuery.browser.mozilla) {
            bookmark.children('a').click(function() {
                window.sidebar.addPanel(title, url, ""); return false;
            });
            bookmark.show();
        }

        if (jQuery.browser.opera) {
            bookmark.children('a').attr("rel", "sidebar");
            bookmark.children('a').attr("href", url);
            bookmark.children('a').attr("title", title);
            bookmark.show();
        }
    }

    if (jQuery('#localDate').length > 0) {
        var todayDate = new Date();
        var localDate = todayDate.toLocaleDateString();
        jQuery('#localDate').html(localDate);
    }

});


function extractFeature(lookup) {
    var query = window.location.search.substring(1);
    var parts = query.split("&");
    for (i = 0; i < parts.length; i++) {
        ft = parts[i].split("=");
        if (ft[0] == lookup) {
            return ft[1];
        }
    }
    return '';
}

function toggleFeature(id) {

    var caller = jQuery('#' + id);

    if (id == active_feature) {
        caller.slideToggle('fast');
        jQuery('#a' + id).children('a').toggle();
    }
    else {
        jQuery('#' + active_feature).slideUp('fast');
        jQuery('#a' + active_feature).children('a').eq(0).show();
        jQuery('#a' + active_feature).children('a').eq(1).hide();
        caller.slideDown('fast');
        jQuery('#a' + id).children('a').eq(0).hide();
        jQuery('#a' + id).children('a').eq(1).show();
    }

    active_feature = id;
}

function OnDealerFocus(elementtId, defaultText) {
    if (document.getElementById(elementtId).value == defaultText) {
        document.getElementById(elementtId).value = "";
    }
}

function OnDealerBlur(elementId, defaultText) {
    var textValue = document.getElementById(elementId).value;
    if (textValue == defaultText || textValue.length == 0) {
        document.getElementById(elementId).value = defaultText;
    }
}

function OnDealerClick(locationId, locationDefaultText, CountryId, CountrNonSelecedValue) {
    var locationValue = document.getElementById(locationId).value;
    var CountryValue = document.getElementById(CountryId).value;

    if (locationValue != locationDefaultText && CountryValue != CountrNonSelecedValue) {
        return true;
    } else {
        return false;
    }
}

function SubmitForm(id, e) {
    var isEnter = window.event == null ? e.keyCode == 13 : window.event.keyCode == 13;
    if (isEnter) document.getElementById(id).click();
}
