
var $jq = jQuery.noConflict();

$jq(function() {
    /*
    * JQuery animation effects
    *
    */

    /* bounce channel buttons */

    $jq("#channels a").click(function() {
        $jq(this).effect("bounce", {}, 400);
        return false;
    });

    $jq("#nav li").hover(
		function() { $jq(this).addClass("hover"); }
		, function() { $jq(this).removeClass("hover"); }
	);

    $jq("#land li").hover(
		function() { $jq(this).addClass("hover"); }
		, function() { $jq(this).removeClass("hover"); }
	);

    $jq("#search input").click(function() {
        $jq(this).css("font-weight", "normal");
        //$jq(this).css("text-transform", "none");
    });


    /*
    * Browser specific fixing 
    *
    */

    var is_chrome = /chrome/.test(navigator.userAgent.toLowerCase());

    // fixing safari
    if ($jq.browser.safari) {
        $jq("body").addClass("sfr");
        //$jq("#search input").val("Safari");
    } //end if

    // fixing chrome
    if (is_chrome) {
        $jq("body").addClass("chr");
        //$jq("#search input").val("Chrome");
    } //end if

    // fixing opera
    if ($jq.browser.opera) {
        $jq("body").addClass("opr");
        //$jq("#search input").val("Opera");
    } //end if

    //if ($.browser.mozilla) {
    if ($jq.browser.mozilla && $jq.browser.version == '1.9.0.13') { // 1.9.1.2 (Firefox 3.5) ... 1.9.0.13 (Firefox 3.0.13)
        $jq("#header").css({ 'margin': '0 0 0 1px' });
    }

    $jq("#popup-error a.close").click(function() {
        $jq("#popup-error").fadeOut();
        return false;
    });


    // slide 1st
    $jq(".slider a.head").click(function() {
        $jq(this).toggleClass("head-on");
        $jq(this).parent().children(".content").slideToggle();

        return false;
    });

    // slide 2nd
    $jq(".slider a.link").click(function() {
        $jq(this).toggleClass("link-on");
        $jq(this).parent().children(".inner-content").slideToggle();

        return false;
    });

    // press/dealer download
    $jq(".box-item-header").click(function() {
        $jq("#" + $jq(this).attr("ref")).toggle();
    });
    $jq(".inner-content").hide();
    $jq(".download-item-image").hide();

    $jq(".download-item-slider-arrow-first").each(function() {
        $jq(this).toggleClass("download-item-slider-arrow-active");
        $jq("#" + $jq(this).attr("ref")).slideToggle();
    });

    $jq(".download-item-slider-arrow").click(function() {
        $jq(this).toggleClass("download-item-slider-arrow-active");
        $jq("#" + $jq(this).attr("ref")).slideToggle();
    });

    $jq(".download-item-container").each(function() {
        var isCollapsed = $jq(this).attr("ref");
        if (isCollapsed == "1") $jq(this).hide();
    });

    $jq("#download-back").click(function() {
        location.href = $jq(this).attr("ref");
    });

});

; (function(jQuery) {

    jQuery.fn.getRealValue = function() {
        if (jQuery(this).get(0).nodeName.toLowerCase() == "select") {
            var vals = [];
            var texts = [];
            jQuery(this).find("option").each(function() {
                vals[vals.length] = jQuery(this).val().replace(/\s+/g, " ").replace(/^\s+/g, "").replace(/\s+$/g, "");
                texts[texts.length] = jQuery(this).text().replace(/\s+/g, " ").replace(/^\s+/g, "").replace(/\s+$/g, "");
            });
            var cur = jQuery(this).nextAll(".newListSelected").find(".selectedTxt").text().replace(/\s+/g, " ").replace(/^\s+/g, "").replace(/\s+$/g, "");
            for (var j in texts) {
                if (cur == texts[j]) {
                    return vals[j];
                    break;
                }
            }
        }
        return jQuery(this).val();
    };

})(jQuery);
