var actual = 1;
var old;

jQuery (document).ready ( function() {


		
	jQuery("#background").ezBgResize();
	
	//jQuery(".wyd").width();
	jQuery(".wyd").each(function (i) {
        jQuery(this).height(jQuery(this).children().children().height()+jQuery(this).children().children().children().height()+8);
        jQuery(this).find('img').width(100);
   });
   
   	jQuery(".ocu_content").each(function (i) {
        var af=(jQuery(this).children().next().height())
        jQuery(this).height(af);
        jQuery(this).find('img').width(100);
   });
	                    
	
	jQuery(".wyd").find('div a').mouseover( function () {
		jQuery(this).addClass( 'title1_bg' );
	}).mouseout( function () {
		jQuery(this).removeClass( 'title1_bg' );
	});
	
	jQuery(".wyd2").find('div a').mouseover( function () {
		jQuery(this).addClass( 'title2_bg' );
	}).mouseout( function () {
		jQuery(this).removeClass( 'title2_bg' );
	});
	
	jQuery("#menu_banner a").click( function () {
		//if ( actual != jQuery(this).attr('class') )
		//{
			var patt = /\d+/gi;
			actual = jQuery(this).attr('class').match(patt);
			actual--;
			if ( actual < 1 ) actual = 0;
			clearInterval(rotate);
			change_banner();
			rotate = setInterval("change_banner()", 10000);
			return false;
		//}
		
	});
	
	rotate = setInterval("change_banner()", 10000);
	
	jQuery("ul.top_submenu li").mouseover( function () {
		jQuery(this).prevAll().stop().animate({ opacity: 0.7});
		jQuery(this).nextAll().stop().animate({ opacity: 0.7});
	}).mouseout( function () {
		jQuery(this).prevAll().stop().animate({ opacity: 1.0});
		jQuery(this).nextAll().stop().animate({ opacity: 1.0});
	});

	change_background();
	back = setInterval("change_background()", 20000);
	
	
	
	jQuery("ul.top_menu li a").mouseover( function () {
			href = jQuery(this).attr('href');
			href = href.replace('/','');
			href = href.replace('/','');
			
			jQuery ("ul.top_submenu").removeClass("mactive");
			jQuery("ul."+href).addClass("mactive");
	});

});

 /*
function change_background()
{
	jQuery("body").animate({ backgroundColor: "#222200"}, 10000);
	jQuery("body").animate({ backgroundColor: "#002201"}, 10000);
	jQuery("body").animate({ backgroundColor: "#002222"}, 10000);
	jQuery("body").animate({ backgroundColor: "#010022"}, 10000);
	jQuery("body").animate({ backgroundColor: "#220022"}, 10000);
	jQuery("body").animate({ backgroundColor: "#220000"}, 10000);
}  */

function change_background()
{
	jQuery("body").animate({ backgroundColor: "#000"}, 20000);
	jQuery("body").animate({ backgroundColor: "#fff"}, 20000);

}


function change_banner()
{
	
	if ( actual < 6 ) actual++;
	else actual = 1;
	
	jQuery("#menu_banner a.active").removeClass("active");
	jQuery("#menu_banner a.m"+String( actual ) ).addClass("active");
	
	jQuery(".rotate_baner").fadeOut('fast', function()
	{
		jQuery(".rotate_baner").html( "<img src=\"/images/banners/banner"+String( actual )+".jpg\" alt=\"Fabryka\" />" );
		jQuery(".rotate_baner").fadeIn('fast');
	});
	
		
}                                    
	
jQuery (window).resize ( function () {

		var cut = Math.round ( ( jQuery("body").width() * 5 ) / 100 );
		var p_cut = Math.round ( cut / 2 );
		
		jQuery("#background").css ( { 'left': p_cut , 'width' : (jQuery("body").width() - cut), 'height' : jQuery("body").height() - 2 } );
		

});
