var pathgfx = '/templates/default/images/';

/*
 * PNGfix init
 */
$(document).ready(function(){
    $(document).pngFix();
});


/*
 * Lightbox
 */
$(function() {
    $('a.lightbox').lightBox();
    $('.gallery a').lightBox();
});


/*
 * Cycle
 */
$(document).ready(function() {
    if($('.splash .slides')) {
        function onBefore() {
            $(this).children('.desc').show();
            $(this).children('.desc').fadeOut(500);
        }
        function onAfter() {
            $(this).children('.desc').hide();
            $(this).children('.desc').fadeIn(300);
        }
        $('.splash .slides').cycle({
            fx: 'fade',
            timeout: 7000,
            speed: 1000,
            before: onBefore,
            after: onAfter
        });
        /*
        $('.splash').hover(function() {
            $('.splash .slides').cycle('pause')
        }, function(){
            $('.splash .slides').cycle('resume')
        });
    /**/
        $('.promo').cycle({
            fx: 'scrollLeft',
            timeout: 5000,
            speed: 1000
        });
        $('#Viz .container').cycle({
            fx: 'scrollUp',
            timeout: 7000,
            speed: 1000
        });
    }
});


/*
 * Nav
 */
$(document).ready(function() {
    $('#HeaderNav .level1 > li').hover(function() {
        $(this).addClass('hover');
    },
    function() {
        $(this).removeClass('hover');
    });
});


/*
 * Search Form
 */
$(document).ready(function() {
    $('#SearchForm .col1 input').click(function(){
        if($(this).val()>0) {
            $('#SearchForm .col1 input#f_invest_0').attr('checked', '');
        } else {
            var checked = $(this).attr('checked');
            
            $('#SearchForm .col1 input').attr('checked', '');
            $('#SearchForm .col1 input#f_invest_0').attr('checked', checked);
        }
    });
});


/*
 * Pop-Up
 */
function showPopUp(cont) {
    $(document).ready(function() {
        $('#Site').append('<div id="popup">'+cont+'<img src="'+pathgfx+'icons/close.png" alt="X" title="" id="popup-close"/></div><div id="popup-bg"></div>');

        var caller = '#popup';
        $(caller).css('position', 'absolute');
        $('#popup-bg').css('width', $('#Site').width()+'px');
        $('#popup-bg').css('height', $('#Site').height()+'px');
        $('#popup-bg').fadeTo(0, 0.75);
    
        var top = ($(window).height() - $(caller).height()) / 2;
        var left = ($(window).width() - $(caller).width()) / 2;

        if(top<25) {
            top = 25;
        }
        if(left<25) {
            left = 25;
        }

        var offset = $('popup-close').offset();
    
        if(offset.top<0) {
            top -= offset.top;
        }
    
        $(caller).css('top', Math.ceil(top)+'px');
        $(caller).css('left', Math.ceil(left)+'px');

        $('#popup-close').click(function(){
            $('#popup-bg').hide();
            $(caller).fadeOut(1000);
        });
        $('#popup-bg').click(function(){
            $('#popup-bg').hide();
            $(caller).fadeOut(1000);
        });
    });
}

