$(document).ready(function() {
        /*$('ul.sf-menu').superfish({
        	autoArrows: false,
        	dropShadows: false,
        	delay: 0,
        	animation:   {opacity:'show',height:'show'},  // fade-in and slide-down animation 
            speed:       'fast'
        });*/
       
       $("ul.main-menu li").hover(function(){
       		if($(this).children('a').hasClass('main-navi-active'))
       			$(this).children('ul.submenu').css('margin-top','5px');
       		$(this).children('ul.submenu').show();	
       	}, function() {
       		if($(this).children('a').hasClass('main-navi-active'))
       			$(this).children('ul.submenu').css('margin-top','0');
       		$(this).children('ul.submenu').hide();
       });
       
       $('ul.submenu').mouseover(function() {
       		if($(this).parent().children('a').hasClass('main-navi'))
       			$(this).parent().children('a').addClass('main-navi-active');
       });
       $('ul.submenu').mouseout(function() {
       		if($(this).parent().children('a').hasClass('main-navi'))
       			$(this).parent().children('a').removeClass('main-navi-active');
       });
       
        for(i=0;i<200;i++)
        {
        	$('#webcam-slide'+i).click(function(){
        		var img_src = $(this).find('a').attr('href');
        	});
       	}
        
        $('#login-tab').click(function() {
        	$('#login-content').toggle("slow");
        });
        
        $('#logout-tab').click(function() {
        	$('#login-content').toggle("slow");
        });
        
        $('body').addClass('js');
        $slideshow.init();  
    	
    	$('.news-latest-container').find('a').each(function(i) {
    		$(this).attr("id","news-"+i);
    	});
    	
    	$('#news-0').click(function() {
    		window.location.href = $(this).attr("href");
    	});
    	
    	$('#news-1').click(function() {
    		window.location.href = $(this).attr("href");
    	});
    	
    	$('#news-2').click(function() {
    		window.location.href = $(this).attr("href");
    	});
    	
    	$('#webcam-slider').cycle({
    		fx: 'fade',
    		speed: 'slow',
    		timeout: 5000,
    		next: '#next',
    		prev: '#prev'
    	});
    	
    	var login_array = getUrlVars();
    	//alert(login_array);
    	if(login_array == 'tx_felogin_pi1%5Bforgot%5D' || login_array == 'tx_felogin_pi1%5Buser%5D,tx_felogin_pi1%5Bforgothash%5D')
    	{
    		$('#login-content').show();
    	}
    	else
    	{
    		
    	}
    	
    	$("#sp1").cycle();
    	$("#sp2").cycle();
});

$slideshow = {
	    context: false,
	    tabs: false,
	    event: 'mouseover',
	    timeout: 4000,      // time before next slide appears (in ms)
	    slideSpeed: 500,   // time it takes to slide in each slide (in ms)
	    tabSpeed: 300,      // time it takes to slide in each slide (in ms) when clicking through tabs
	    fx: 'fade',

	    init: function() {
	        // set the context to help speed up selectors/improve performance
	        this.context = $('#news');

	        // set tabs to current hard coded navigation items
	        this.tabs = $('ul.news-latest-container li', this.context);

	        // remove hard coded navigation items from DOM
	        // because they aren't hooked up to jQuery cycle
	        this.tabs.remove();

	        // prepare slideshow and jQuery cycle tabs
	        this.prepareSlideshow();
	    },

	    prepareSlideshow: function() {
	        // initialise the jquery cycle plugin -
	        // for information on the options set below go to:
	        // http://malsup.com/jquery/cycle/options.html
	        $("div.news-list-container > ul", $slideshow.context).cycle({
	            fx: $slideshow.fx,
	            timeout: $slideshow.timeout,
	            speed: $slideshow.slideSpeed,
	            fastOnEvent: $slideshow.tabSpeed,
	            pager: $("ul.news-latest-container", $slideshow.context),
	            pagerAnchorBuilder: $slideshow.prepareTabs,
	            pagerEvent: 'mouseover',
	            before: $slideshow.activateTab,
	            pauseOnPagerHover: true,
	            pause: true
	        });
	    },

	    prepareTabs: function(i, slide) {
	        // return markup from hardcoded tabs for use as jQuery cycle tabs
	        // (attaches necessary jQuery cycle events to tabs)
	    	return $slideshow.tabs.eq(i);
	    },

	    activateTab: function(currentSlide, nextSlide) {
	        // get the active tab
	        var activeTab = $('a[href="#' + nextSlide.id + '"]', $slideshow.context);
	        
	        // if there is an active tab
	        if(activeTab.length) {
	        	
	            // remove active styling from all other tabs
	            $slideshow.tabs.removeClass('on');

	            // add active styling to active button
	            activeTab.parent().addClass('on');
	        }
	    }
};

function getUrlVars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}

