jQuery(document).ready(function(){

    /*
     jQuery('#one').cycle({
     fx: 'scrollLeft',
     next: '#next',
     prev: '#prev',
     pager: '#nav',
     nowrap: 1,
     delay: -5000,
     speed: 5000,
     timeout: 10000
     });
     */
    jQuery('.current-product').hover(function(e){
        var elementID = '#' + jQuery(this).parent().attr('id');
        jQuery('#content').html('');
        jQuery('#content').html(jQuery(elementID + ' .intro').html());
        jQuery('#content').fadeIn('slow');
        var topPos = jQuery(this).offset().top + 70;
        var leftPos = jQuery('#page').offset().left + 90;
        jQuery('#content').css({
            position: 'absolute',
            top: topPos,
            left: leftPos
        });
    }, function(e){
        jQuery('#content').hide();
    });
    
    jQuery('.accessories a').click(function(){
        newWindowWithURL($(this).attr('href'));
        return false;
    });
    
    jQuery('div#nav').find('a').each(function(i){
        var value = jQuery(this).html();
        jQuery(this).addClass('nav-element group-' + i);
        jQuery(this).html('<span>' + value + '<\/span>');
    });
    
    var config = {
        over: intentIn, // function = onMouseOver callback (REQUIRED)    
        timeout: 2000, // number = milliseconds delay before onMouseOut    
        out: intentOut // function = onMouseOut callback (REQUIRED)    
    };
    jQuery('.li-level-1').hoverIntent(config);
    
    function intentIn(){
    }
    function intentOut(){
    }
    /*
     jQuery('ul.ul-level-2 li a').not('.selected').hover(function(){
     jQuery(this).children().animate({
     opacity: "1.0",
     color: "#fff"
     }, 200);
     }, function(){
     jQuery(this).children().animate({
     opacity: "0.9",
     color: "#f1f1f1"
     }, 200);
     });
     */
});

var wWith = 800;
var wHeight = 600;
var windowName = 'Accessori';
var windowOptions = 'resizable=yes,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes';
function newWindowWithURL(anHref){
    var queryString = anHref.replace(/^[^\?]+\??/, '');
    var params = xp_parseQuery(queryString);
    if (params['width'] != null && params['width'] != '') 
        wWith = params['width'];
    if (params['height'] != null && params['height'] != '') 
        wHeight = params['height'];
    if (anHref != null && anHref != '' && anHref != '#') {
        var newWindow = window.open(anHref, windowName, windowOptions + ',width=' + wWith + ',height=' + wHeight);
        newWindow.focus();
    }
}

function xp_parseQuery(query){
    var Params = {};
    if (!query) {
        return Params;
    }// return empty object
    var Pairs = query.split(/[;&]/);
    for (var i = 0; i < Pairs.length; i++) {
        var KeyVal = Pairs[i].split('=');
        if (!KeyVal || KeyVal.length != 2) {
            continue;
        }
        var key = unescape(KeyVal[0]);
        var val = unescape(KeyVal[1]);
        val = val.replace(/\+/g, ' ');
        Params[key] = val;
    }
    return Params;
}
