/**
* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
*/
(function(jQuery){
    jQuery.fn.hoverIntent=function(f,g){
        var cfg={
            sensitivity:7,
            interval:100,
            timeout:0
        };

        cfg=jQuery.extend(cfg,g?{
            over:f,
            out:g
        }:f);
        var cX,cY,pX,pY;
        var track=function(ev){
            cX=ev.pageX;
            cY=ev.pageY;
        };

        var compare=function(ev,ob){
            ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);
            if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){
                jQuery(ob).unbind("mousemove",track);
                ob.hoverIntent_s=1;
                return cfg.over.apply(ob,[ev]);
            }else{
                pX=cX;
                pY=cY;
                ob.hoverIntent_t=setTimeout(function(){
                    compare(ev,ob);
                },cfg.interval);
            }
        };

        var delay=function(ev,ob){
            ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);
            ob.hoverIntent_s=0;
            return cfg.out.apply(ob,[ev]);
        };

        var handleHover=function(e){
            var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;
            while(p&&p!=this){
                try{
                    p=p.parentNode;
                }catch(e){
                    p=this;
                }
            }
            if(p==this){
                return false;
            }
            var ev=jQuery.extend({},e);
            var ob=this;
            if(ob.hoverIntent_t){
                ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);
            }
            if(e.type=="mouseover"){
                pX=ev.pageX;
                pY=ev.pageY;
                jQuery(ob).bind("mousemove",track);
                if(ob.hoverIntent_s!=1){
                    ob.hoverIntent_t=setTimeout(function(){
                        compare(ev,ob);
                    },cfg.interval);
                }
            }else{
                jQuery(ob).unbind("mousemove",track);
                if(ob.hoverIntent_s==1){
                    ob.hoverIntent_t=setTimeout(function(){
                        delay(ev,ob);
                    },cfg.timeout);
                }
            }
        };

        return this.mouseover(handleHover).mouseout(handleHover);
    };

})(jQuery);

jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        options.path = '/';
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

function obscureMid() {
    document.write('@');
}
function obscureEnd() {
    document.write('.');
}


jQuery(document).ready(function(){

    // acordion
    jQuery(".csc-frame-accordion").each(function () {
        $(this).addClass('hide');
        $(this).find('h1,h2,h3').addClass('accordion-header');
        $(this).find('h1,h2,h3').remove().insertBefore(this);
        $(this).parent().addClass('accordion-nest');

    });

    jQuery('.accordion-header').click(function(el) {
        $(this).next().toggleClass('hide');
        $(this).parent().toggleClass('csc-frame-accordion-active');
    });


    function makeTall() {
        jQuery(this).addClass("showsub");
        jQuery(this).addClass("active");
    }
    function makeShort() {
        jQuery(this).removeClass("showsub");
        jQuery(this).removeClass("active");
    }

    // lightbox
    jQuery("a[rel^='prettyPhoto']").prettyPhoto({
        default_width: 980,
        default_height: 510,
        theme: 'light_square',
        allow_resize: false,
        counter_separator_label: ' / ',
        gallery_markup: '<div class="pp_gallery"> \
					</div>'
    });



    var config = {
        over: makeTall, // function = onMouseOver callback (REQUIRED)
        timeout: 100, // number = milliseconds delay before onMouseOut
        out: makeShort // function = onMouseOut callback (REQUIRED)
    };
    var configProductNavi = {
        over: makeTall, // function = onMouseOver callback (REQUIRED)
        timeout: 200, // number = milliseconds delay before onMouseOut
        out: makeShort // function = onMouseOut callback (REQUIRED)
    };

    jQuery("#main-navigation li.menu-level1").hoverIntent( config );
    jQuery("#product-navigation li.menu-level1").hoverIntent( configProductNavi );
    jQuery(".nav-search a").click(function() {
        $(this).parent().parent().parent().toggleClass('active');
    });
    //    $('.power_parts_body').hide();
    $('.power_parts').click(function(){
        temp=$(this).attr('custom');
        $('.power_parts_body').hide();
        $('#'+temp).show();
        return false;
    })
    $('#main-navigation ul li').click(function(){
            location.replace($(this).attr('id'));
//        alert($(this).attr('id'))
        
    })
 
});




