cur = null;
t = 500;

$(document).ready(function(){

/*	$('a[@rel*=lightbox]').lightBox({
		imageLoading: '../templates/images/preloader.gif',
		imageBtnClose: 'templates/images/g_close.png',
		imageBtnPrev: '../templates/images/g_previous.png',
		imageBtnNext: '../templates/images/g_next.png',
	}); */

	$('div.videoBox a').click(function(){
		$(this).parent('div').height(310);
		$(this).blur();
		$(this).next('object').show();
		return false;
	})

	$('a.dwapigroup').hoverIntent(function(){
		$(this).children('img').fadeIn(200);
	},function(){
		$(this).children('img').fadeOut(200);
	})

	$('div.struktura_blok h3 a:not(.real_link)').click(function(){
		if ($(this).hasClass('blok_open'))
		{
			$(this).parent().next('div').slideUp(t).animate({opacity: 0},{queue: false, duration: t});
			$(this).removeClass();
		}
		else
		{
			$('div.struktura_blok h3 a').removeClass();
			$('div.struktura_blok ul li div').slideUp(t).animate({opacity: 0},{queue: false, duration: t});
			$(this).parent().next('div').css('opacity',0);
			$(this).parent().next('div').slideDown(t).animate({opacity: 1},{queue: false, duration: t});
			$(this).addClass('blok_open');
		}
		return false;
	})

	$('a[rel=outer_link]').click(function(){
		var newWindow = window.open($(this).attr('href'), '_blank');
		newWindow.focus();
		return false;
	})

	$('#partnerzy div.cycle').cycle({ 
	    fx:    'custom', 
	    cssBefore: {position: 'absolute', opacity: 0, left: 170, top: 0, display: 'block' },
	    animIn: {opacity: 1, left: 0, top: 0},
	    animOut: {opacity: 0, left: -170, top: 0},
	    speed:  1000,
	    next: '#partnerzy a.right',
	    prev: '#partnerzy a.left',
	    prevNextClick: function(isNext, zeroBasedSlideIndex, slideElement){
	    	if (isNext)
	    	{
				this.cssBefore.left = -170;
				this.animOut.left = 170;
			}
			else
			{
				this.cssBefore.left = 170;
				this.animOut.left = -170;
			}
	    },
	    startingSlide: Math.floor(Math.random()*$('#partnerzy div.cycle img').length),
	    timeout: 9000,
	    before: function(){$('#partnerzy p.title').text($(this).attr('title'));}
	});
	
	$('#sponsorzy div.cycle').cycle({ 
		delay: 3000,
	    fx:    'custom', 
	    cssBefore: {position: 'absolute', opacity: 0, left: 170, top: 0, display: 'block' },
	    animIn: {opacity: 1, left: 0, top: 0},
	    animOut: {opacity: 0, left: -170, top: 0},
	    speed:  1000,
	    next: '#sponsorzy a.right',
	    prev: '#sponsorzy a.left',
	    prevNextClick: function(isNext, zeroBasedSlideIndex, slideElement){
	    	if (isNext)
	    	{
				this.cssBefore.left = -170;
				this.animOut.left = 170;
			}
			else
			{
				this.cssBefore.left = 170;
				this.animOut.left = -170;
			}
	    },
	    startingSlide: Math.floor(Math.random()*$('#sponsorzy div.cycle img').length),
	    timeout: 9000,
	    before: function(){$('#sponsorzy p.title').text($(this).attr('title'));}
	});
	
	$('#patroni div.cycle').cycle({ 
		delay: 6000,
	    fx:    'custom', 
	    cssBefore: {opacity: 0, left: 170, top: 0, display: 'block' },
	    animIn: {opacity: 1, left: 0, top: 0},
	    animOut: {opacity: 0, left: -170, top: 0},
	    speed:  1000,
	    next: '#patroni a.right',
	    prev: '#patroni a.left',
	    prevNextClick: function(isNext, zeroBasedSlideIndex, slideElement){
	    	if (isNext)
	    	{
				this.cssBefore.left = -170;
				this.animOut.left = 170;
			}
			else
			{
				this.cssBefore.left = 170;
				this.animOut.left = -170;
			}
	    },
	    startingSlide: Math.floor(Math.random()*$('#patroni div.cycle img').length),
	    timeout: 9000,
	    before: function(){$('#patroni p.title').text($(this).attr('title'));}
	});	

	// Show first news
	$('div.news_content:eq(0)').css('display','block');
	$('ul.news_box a:eq(0)').addClass('selected');
	
	// Add id's to news links	
	$('ul.news_box a').each(function (i){
		$(this).attr('n',i);
	})	
	
	// Show news on click
	$('ul.news_box a').click(function(){
		if (!$(this).hasClass('selected'))
		{
			i = $(this).attr('n');
			$('ul.news_box a').removeClass();		
			$(this).addClass('selected');
			$('div.news_content').fadeOut(500);
			$('div.news_content:eq('+i+')').fadeIn(500);
		}
		return false;
	});
	
	// Ipma logo
	$('img.ipma').css('opacity',0.5);
	$('img.ipma').hoverIntent(function(){
		$(this).animate({'opacity': 1},200);
	},function(){
		$(this).animate({'opacity': 0.5},200);
	})

	// Add id's to submenus	
	$('#menu ul').each(function (i){
		$(this).attr('id','submenu'+i);
	})

	// Add hover to menu buttons
	$('#menu > a').hoverIntent(function(){
		$(this).animate({'opacity': 0.5},200);
	},function(){
		$(this).animate({'opacity': 1},200);
	})

	// Show submenu's on click
	$('#menu a.sub').click(function(){
		el = $(this).next();
		if ($(cur).attr('id') == $(el).attr('id'))
		{
			cur = null;
			this.state = 0;
			$(el).slideUp(t).animate({opacity: 0},{queue: false, duration: t});
			return false;
		}
		else
		{
			$(cur).slideUp(t).animate({opacity: 0},{queue: false, duration: t});
			cur = el;
			this.state = 1;
			$(cur).css('opacity',0);
			$(cur).slideDown(t).animate({opacity: 1},{queue: false, duration: t});		
			return false;			
		}
	});
});

function openMenu(id)
{
	id--;
	$('#menu ul:eq('+id+')').css('display','block');
	cur = $('#menu ul:eq('+id+')');
}

function openBlock(id)
{
	$(document).ready(function(){
		$.scrollTo('div.struktura_blok:has(#'+id+')',{
			duration: 1000, 
			offset: {left: 0, top: -10}, 
			onAfter: function(){
				$('#'+id+' a').click(); 
				setTimeout("$('#"+id+"').css('font-weight','bold');",600);
				setTimeout("$('#"+id+"').css('font-weight','normal');",3000);
			}
		});
	});
}

var scrollSettings = {
			duration: 1000, 
			offset: {left: 0, top: -10}
			}
