jQuery(document).ready(function(){

    jQuery('.widget_qtranslate a.language').live('click', function(){
        jQuery(this).next('ul').slideToggle();
        return false;
    });

    jQuery('#menu-main > li > a').live('click', function(){
        if(jQuery(this).next('ul').length > 0){
            /*jQuery(this).next('ul').children('li:first').children('a').click();*/
            window.location.href = jQuery(this).next('ul').children('li:first').children('a').attr('href');
            return false;
        }
    });

    jQuery('.product-select select').live('change', function(){
        var e = jQuery(this);
        e.prev().text(e.find(':selected').html());
        jQuery.ajax({
            url:site.templateDirectory + '/ajax.php?method=' + e.attr('method') + '&id=' + e.val(),
            type:'post',
            dataType:'json',            
            success:function(data){
                var s = e.parent().next().next().children('select');
                if(s.length > 0){
                    s.children('option:not(:first)').remove();
                    for(x in data){
                        s.append('<option permalink="' + data[x].permalink + '" value="' + data[x].ID + '">' + data[x].post_title + '</option>');
                    }
                } else {
                    window.location.href = e.find(':selected').attr('permalink');
                }
            }
        });
    });

    jQuery('ul.pages li a').live('click', function(){
        var e = jQuery(this);
        if(e.parent().children('ul').length > 0){
            e.parent().children('ul').slideToggle();
            return false;
        }
    });

    jQuery('body.page .gallery a img').each(function(i, e){
        jQuery(e).parent().attr({
            href: jQuery(e).attr('alt'),
            target: '_blank'
        });        
        setTimeout(function(){
            jQuery(e).css({paddingTop: (150-jQuery(e).height()) * 0.5});
        }, 200);
    })

    jQuery('#menu-footer li a').live('click', function(){
        if(jQuery(this).next('ul').length > 0){
            jQuery(this).next('ul').children('li:first').children('a:first').click();
            return false;
        } else {
            window.location.href = jQuery(this).attr('href');
            return false;
        }
    });

    jQuery.css3selectors();
    
})
