(function ($) {$(document).ready(function () {

	$('#header #block-system-main-menu .content > ul li').each(function(){
		if( $(this).hasClass('expanded') )
		{
			if( !$(this).hasClass('processed_by_JS') )
			{
				$(this).addClass('processed_by_JS');
				$arrDown = $('<img />');
				$arrDown.attr({'src' : 'sites/all/themes/softnet/images/rozwijane_menu_arrow.png', 'alt' : ''});
				$arrDown.css({'position' : 'absolute', 'top' : '0', 'left' : '50%', 'margin-left' : '-7px', 'margin-top' : '-7px', 'z-index' : '3'});
				$(this).children('ul:first').prepend($arrDown);
			}
		}
	});
	$('#header #block-system-main-menu .content > ul li').hover(function() {
		$ul_w = $(this).children('ul:first').width();
			$(this).children('ul:first').css({'left':'50%', 'margin-left':'-'+($ul_w/2.0)+'px'});
		});

	// If the browser is IE,
	if( $.browser.msie && parseInt($.browser.version) < 8 )
	{
		/*
		** For each div with class menu (i.e.,
		** the thing we want to be on top),
		*/
		$("div.menu").parents().each(function() {
			var p = $(this);
			var pos = p.css("position");
 
			// If it's positioned,
			if(pos == "relative" ||
			   pos == "absolute" ||
			   pos == "fixed")
			{
				/*
				** Add the "on-top" class name when the
				** mouse is hovering over it, and remove
				** it when the mouse leaves.
				*/
				p.hover(function() {
						$(this).addClass("on-top");
					},
					function() {
						$(this).removeClass("on-top");
					});
			}
		});
	}
	
	$('.webform-client-form input.form-submit').hide().after('<span class="send-button"></span>').next('span.send-button').click(function(){
        $(this).prev('.webform-client-form input.form-submit').click();
	});
	
	if( $('.front .front-news:first').height() > $('.front .front-news-right').height() )
	{
		$('.front .front-news-right').height($('.front .front-news:first').height());
	}
	else
	{
		$('.front .front-news:first').height($('.front .front-news-right').height());
	}
	
	if( ($('.not-front #content > .section').height()+4) < $('#sidebar-first').height() )
	{
		$('.not-front #content > .section').height($('#sidebar-first').height()-36);
	}
	else
	{
		$('#triptych-wrapper').css({'margin-top':'0'});
	}
	
	if( $('.node-type-article .field-name-field-image img').length )
	{
		var img = $('.node-type-article .field-name-field-image img'); // Get my img elem
		var pic_real_width, pic_real_height;
		$("<img/>") // Make in memory copy of image to avoid css issues
			.attr("src", $(img).attr("src"))
			.load(function() {
				pic_real_width = this.width;   // Note: $(this).width() will not
				pic_real_height = this.height; // work for in memory images.
				
				
		//max width
		if( pic_real_width > 200 ) { $('.node-type-article .field-name-field-image img').width(200); pic_real_width = 200 }
		$('.node-type-article .field-name-field-image img').css({'margin':'0'});
		$('.node-type-article .field-name-field-image img').after('<img src="sites/all/themes/softnet/images/shadow.png" width="'+pic_real_width+'" alt="" />');
		$('.field-name-field-image').css({'width':pic_real_width+'px', 'vertical-align':'top', 'display':'inline-block', 'padding-right':'10px'});
		$('.field-name-body').css({'display':'inline-block', 'width':( $('.field-name-body').parent().width()-$('.field-name-field-image').width()-10 )+'px', 'line-height':'18px'});
				
				
			});

	

	}
	
	$('.region-triptych-middle .content div').hide();
	$('.region-triptych-middle .content div:first').show();
	
	setInterval( function(){jQuery_rotate();}, 5000);
	
	function jQuery_rotate()
	{		
		if( $('.region-triptych-middle .content div:visible').next().length == 0 )
		{
			$('.region-triptych-middle .content div:visible').fadeOut(1000);
			$('.region-triptych-middle .content div:first').fadeIn(1000);
		}
		else
		{
			$('.region-triptych-middle .content div:visible').next().fadeIn(1000).prev().fadeOut(1000);
		}
	}
	
});})(jQuery);;

