var IE = document.all ? true : false;
if (!IE) document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = getMouseXY;
var tempX = 0;
var tempY = 0;

function getMouseXY(e) {
    if (IE) {
        tempX = event.clientX + (document.documentElement||document.body).scrollLeft;
        tempY = event.clientY + (document.documentElement||document.body).scrollTop;
    } else {
        tempX = e.pageX;
        tempY = e.pageY;
    }
    if (tempX < 0){
        tempX = 0;
    }
    if (tempY < 0){
        tempY = 0;
    }
    return true;
}

function getWindowHeight() {
    if( typeof( window.innerWidth ) == 'number' ) {
        return window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        return document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        return document.body.clientHeight;
    } else {
        return 0;
    }
}

function getWindowWidth() {
    var myWidth = 0;
    if( typeof( window.innerWidth ) == 'number' ) {
        myWidth = window.innerWidth;
    }
    else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        myWidth = document.documentElement.clientWidth;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        myWidth = document.body.clientWidth;
    }
    return myWidth;
}

jQuery().ready(function() 
{
    jQuery('.breadcrumbs li:last').children('a').css('color', '#e22a96');

    if(jQuery('#menu_left ul:first li').not('#menu_left ul li ul li').length == 1)
    {
        jQuery('#menu_left ul:first li').children('ul').css('display', 'block');
        jQuery('#menu_left ul li a:first').css('background-image', 'none');
    }
    else
    {
        jQuery('.li_active').parent('ul').css('display', 'block');
        jQuery('.li_active').parent('ul').parent('li').parent('ul').css('display', 'block');
        jQuery('.li_active').children('ul').css('display', 'block');
        if(jQuery('a.active').css('color' == 'rgb(255, 255, 255)'))
        {
            jQuery('a.active').addClass('minus');
            jQuery('a.active').parent('li').parent('ul').parent('li').children('a').addClass('minus');
        }
    }

    

//    jQuery('.product_popup').click(function() {
//        var url = jQuery(this).attr('href');
//        showPopupProduct(url)
//        return false;
//    });

    jQuery('#products_email').click(function() {
        var windowW=400;
        var windowH=300;
        var windowX = Math.floor((screen.availWidth/2)-(windowW/2));
        var windowY = Math.floor((screen.availHeight/2)-(windowH/2));
        config='toolbar=0,location=0,directories=0,status=0,scrollbars=3,resizable=0'
        config +=',width=' + windowW + ',height=' + windowH + ',left=' + windowX + ',top=' + windowY + ',menubar=0' ;

        var href = jQuery(this).attr('href');

        emailWindow = window.open(href, 'Powiadom_znajomego', config);

        return false;
    });

    var popup_request = jQuery('#popup_request').text();
    if(parseInt(popup_request) > 0)
    {
        var url = '/pl/popup/' + popup_request + '/slug.html';        
        showPopupProduct(url)        
    }

    function showPopupProduct(url)
    {
        var windowW=650;
        var windowH=700;
        var windowX = Math.floor((screen.availWidth/2)-(windowW/2));
        var windowY = Math.floor((screen.availHeight/2)-(windowH/2));
        config='toolbar=0,location=0,directories=0,status=0,scrollbars=3,resizable=0'
        config +=',width=' + windowW + ',height=' + windowH + ',left=' + windowX + ',top=' + windowY + ',menubar=0' ;      
        productWindow = window.open(url, 'Produkt', config);
        return false;
    }

    jQuery('.tr_acc').mouseover(function() {
        jQuery(this).css('cursor', 'pointer');
        jQuery(this).children('td').css('background', '#e0e0e0');
    })

    jQuery('.tr_acc').mouseout(function() {
        jQuery(this).children('td').css('background', 'none');
    })

    jQuery('.tr_acc').click(function() {
        var href = jQuery(this).children('td').children('a.product_popup').attr('href');
        window.open(href);      
    })
    
});
