/* site.js */


$(function() {
    $('.aligncolumns').each(function() {
        var obj = $(this);
        var left = obj.children('.leftcolumn');
        var right = obj.children('.rightcolumn');
        var height = left.height() > right.height() ? left.height() : right.height();
        left.height(height);
        right.height(height);
    });
    /* Add separators in menu */
    $('#menu #first A:not(:first), #menu #second A:not(:first), #menu #third A:not(:first)').before('<div class="separator">|</div>');

    /* Watermark for search box */
    $('.searchbox').click(function() { var obj = $(this); if (obj.val() == 'SEARCH') { obj.val(''); } else { obj.select(); } });
    $('.searchbox').blur(function() { var obj = $(this); if (obj.val() == '') { obj.val('SEARCH'); } });

    /* Add connectors */
    $('.box:not(:first)').each(function() {
        $(this).prepend('<img src="./images/ooo_vertical.png" alt="" class="ooo_vertical" style="z-index: 100;"/>');
    });
    $('.box:first .ooo_vertical').hide(); /* IE hack */

    var height = $('#main').height();
    /* Hide connectors below the main area */
    $('.box .ooo_horizontal').each(function() {
        var obj = $(this);
        if (obj.offset().top > height) {
            obj.attr('src', './images/1px.gif');
        }
    });

    /* Add vertical connectors below the main area */
    $('.box').each(function() {
        var obj = $(this);
        if (obj.offset().top + 20 > height) {
            $(this).prepend('<img src="./images/ooo_vertical.png" alt="" class="ooo_vertical2" style="z-index: 100;"/>');
        }
    });

    /* Remove padding on last LI in UL with class newslist */
    $('.newslist').find('LI:last').css('padding', '0');

    $('UL.tabs').each(function() {
        var obj = $(this);
        obj.wrap('<div class="tabbedpanel"></div>');
        var counter = 0;
        obj.children('LI:not(.separator)').each(function() {
            $(this).addClass('tab' + counter).children('UL').addClass('tab' + counter).hide().appendTo(obj.parent());
            $(this).click(function() {
                $(this).css('color', '#000000');
                $(this).siblings().css('color', '#837870');
                $(this).parent().parent().children(':not(:first)').hide();
                $(this).parent().parent().children('.' + $(this).attr('class')).show();
            });
            counter++;
        });
        obj.children(':not(:first)').css('color', '#837870');
        obj.children(':first').css('color', '#000000');
        obj.siblings('UL:first').show();
    });


    var cookie = $.cookie('firstuse');
	if (cookie == null || cookie != 'true') {
		var date = new Date();
		date.setTime(date.getTime() + (365 * 24 * 60 * 60 * 1000));
        $.cookie('firstuse', 'true', { path: '/', expires: date })
        var width = $(window).width();
        var height = $(window).height();
        var dheight = $(document).height();

        var obj = $('<div class="popup"><div class="padding"><div id="popupflash"></div></div></div>').css('top', ((height / 2) - 224) + 'px').css('left', ((width / 2) - 284) + 'px').click(function(e) { var x = e.pageX - this.offsetLeft; var y = e.pageY - this.offsetTop; if (x >= 11 && x <= 18 && y >= 10 && y <= 17) { return true; } return false; });

        var container = $('<div class="overlay"></div>').css('height', dheight + 'px').click(function() { $(this).fadeOut('fast', function() { $(this).remove(); }); }).append(obj)
        $('BODY').append(container);

        swfobject.embedSWF("flash/introfilm.swf", "popupflash", "490", "276", "10.0.0");
    }

    $('.newsdeskcontent A').attr('target', '_blank');
});

