jQuery.jqURL = {
    url: function(args){
        args = jQuery.extend({
            win: window
        }, args);
        return args.win.location.href;
    },
    loc: function(urlstr, args){
        args = jQuery.extend({
            win: window,
            w: 500,
            h: 500,
            wintype: '_top'
        }, args);
        if (!args.t) {
            args.t = screen.height / 2 - args.h / 2;
        }
        if (!args.l) {
            args.l = screen.width / 2 - args.w / 2;
        }
        if (args['wintype'] == '_top') {
            args.win.location.href = urlstr;
        }
        else {
            open(urlstr, args['wintype'], 'width=' + args.w + ',height=' + args.h + ',top=' + args.t + ',left=' + args.l + ',scrollbars,resizable');
        }
        return;
    },
    qs: function(args){
        args = jQuery.extend({
            ret: 'string',
            win: window
        }, args);
        if (args['ret'] == 'string') {
            return jQuery.jqURL.url({
                win: args.win
            }).split('?')[1];
        }
        else 
            if (args['ret'] == 'object') {
                var qsobj = {};
                var thisqs = jQuery.jqURL.url({
                    win: args.win
                }).split('?')[1];
                if (thisqs) {
                    var pairs = thisqs.split('&');
                    for (i = 0; i < pairs.length; i++) {
                        var pair = pairs[i].split('=');
                        qsobj[pair[0]] = pair[1];
                    }
                }
                return qsobj;
            }
    },
    strip: function(args){
        args = jQuery.extend({
            keys: '',
            win: window
        }, args);
        if (jQuery.jqURL.url().indexOf('?') == -1) {
            return jQuery.jqURL.url({
                win: args.win
            });
        }
        else 
            if (!args.keys) {
                return jQuery.jqURL.url({
                    win: args.win
                }).split('?')[0];
            }
            else {
                var qsobj = jQuery.jqURL.qs({
                    ret: 'object',
                    win: args.win
                });
                var counter = 0;
                var url = jQuery.jqURL.url({
                    win: args.win
                }).split('?')[0] +
                '?';
                var amp = '';
                for (var key in qsobj) {
                    if (args.keys.indexOf(key) == -1) {
                        amp = (counter) ? '&' : '';
                        url = url + amp + key + '=' + qsobj[key];
                        counter++;
                    }
                }
                return url;
            }
    },
    get: function(key, args){
        args = jQuery.extend({
            win: window
        }, args);
        qsobj = jQuery.jqURL.qs({
            ret: 'object',
            win: args.win
        });
        return qsobj[key];
    },
    set: function(hash, args){
        args = jQuery.extend({
            win: window
        }, args);
        var qsobj = jQuery.jqURL.qs({
            ret: 'object',
            win: args.win
        });
        for (var i in hash) {
            qsobj[i] = hash[i];
        }
        var qstring = '';
        var counter = 0;
        var amp = '';
        for (var k in qsobj) {
            amp = (counter) ? '&' : '';
            qstring = qstring + amp + k + '=' + qsobj[k];
            counter++;
        }
        return jQuery.jqURL.strip({
            win: args.win
        }) +
        '?' +
        qstring;
    }
};

function initMenus(){
    $('ul.menu ul').hide();
    $.each($('ul.menu'), function(){
        var cookie = $.cookie(this.id);
        if ($.jqURL.get(this.id) != null) {
            $('#' + this.id + ' .' + $.jqURL.get(this.id)).next().show();
        }
        else 
            if (cookie != null && String(cookie).length < 1) {
                $('#' + this.id + '.expandfirst ul:first').show();
            }
            else {
                $('#' + this.id + ' .' + cookie).next().show();
            }
    });
    $('ul.menu li a').click(function(){
    
        var checkElement = $(this).next();
        //var parent = this.parentNode.parentNode.id;
		var parent = $('ul.menu').attr('id');
        
        if ($('#' + parent).hasClass('noaccordion')) {
            if ((String(parent).length > 0) && (String(this.className).length > 0)) {
                if ($(this).next().is(':visible')) {
                    $.cookie(parent, null);
                }
                else {
                    $.cookie(parent, this.className);
                }
                $(this).next().slideToggle('normal');
            }
        }
        if ((checkElement.is('ul')) && (checkElement.is(':visible'))) {
            if ($('#' + parent).hasClass('collapsible')) {
                $('#' + parent + ' ul:visible').slideUp('normal');
            }
            return false;
        }
        if ((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
            $('#' + parent + ' ul:visible').slideUp('normal');
            if ((String(parent).length > 0) && (String(this.className).length > 0)) {
                $.cookie(parent, this.className);
            }
            checkElement.slideDown('normal');
            return false;
        }
    });
}



var headline_count;
var headline_interval;
var old_headline = 0;
var current_headline = 0;
$(document).ready(function(){

    headline_count = $("div.headline").size();
    $("div.headline:eq(" + current_headline + ")").css('top', '5px');
    headline_interval = setInterval(headline_rotate, 5000);
    /*	$('#scrollup').hover(function() {
     clearInterval(headline_interval);
     }, function() {
     headline_interval = setInterval(headline_rotate,5000);
     headline_rotate();
     });*/
    initMenus();
    
    
    
    // search link
    $("form.searchside a.searchside").click(function(){
        $("form.searchside").submit();
        return false;
    });
    $("div.search a.go").click(function(){
        $("div.search form").submit();
        return false;
    });
    
});
function headline_rotate(){
    current_headline = (old_headline + 1) % headline_count;
    $("div.headline:eq(" + old_headline + ")").animate({
        top: -205
    }, "slow", function(){
        $(this).css('top', '600px');
    });
    $("div.headline:eq(" + current_headline + ")").animate({
        top: 5
    }, "slow");
    old_headline = current_headline;
}