/**
 * @author KAMIL
 */

$(document).ready(function(){
	
//	$('div.pag').find('a.selected').parent().parent().css('background-image: url(images/select_toc.gif)');
	if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
 			var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
			if (ieversion<=7)
			{
				title = document.title;
				url = window.location.href;
				$('#addtofavourite').click(function(){ 
					window.external.AddFavorite(url,title);
				});
			} else
			{	
				//ie8
				$('#addtofavourite').jFav();
			}	
 
		} else {
			$('#addtofavourite').jFav();
		}
	
	//$('a.sharethis').sharethis('http://w.sharethis.com/button/sharethis.js#headerTitle=ShareThis%20Widget');	
		
	var strona = $('#active').attr('rel');
	if (strona == 'home' || strona == '') strona = 'node-6';



	$('li').removeClass('currentpage');
	
/*	if (strona == 'gallery-ludzie1'){strona = 'node-32';}
	if (strona == 'gallery-album2'){strona = 'node-19';}
	if (strona == 'gallery-album3'){strona = 'node-20';}
	if (strona == 'gallery-album4'){strona = 'node-21';}
	if (strona == 'gallery-album5'){strona = 'node-28';}
*/	
	if (strona == 'home-stocks'){strona = 'node-6-stocks';}
	if (strona == 'home-cips'){strona = 'node-11';}
	if (strona == 'home-contact'){strona = 'node-13';}

	
	$('.menu-path-'+strona).addClass('currentpage');
	$('.menu-path-'+strona+' a').addClass('active');
	
	// zmiana title
	
	var title=$('.about-title').html();
	if (title == null){
		var title = $('.image-preview img').attr('title');
	}

/*	
	if (title != null && title != '') {
		title = '<h2>' + title + '</h2>';
		$('#mission-title').html(title);
	}	
	
*/	
	$('.slimbox li').each(function(){
		var h = $(this).find('a').height();
		if (h > 20) {
			h = h + 6;
		}else{
			h=20;
		} 
		$(this).height(h);
	});


 
	//zmiana wielkości obrazków w blocku
	var w = $('.view-gallerymain img').attr('width');
	var h = $('.view-gallerymain img').attr('height');
	var ratio = w/h;
	var h1 = 52/ratio;
	$('.view-gallerymain img').attr('width','52');
	$('.view-gallerymain img').attr('height',h1);
	$('.view-gallerymain .image-title').hide();
	
	
	//nice-menu
	var left = 0;
	$('#nice-menu-6').children('li').each(function(){
		$(this).children('ul').each(function(){
					$(this).css('left',-left);
					$(this).children('li').each(function(){
						var width = $(this).find('a').width();
						$(this).width(width+30);
					});
		});
		left = left + $(this).width();
	});
	
	$('#nice-menu-6').children('li').each(function(){
		if ($(this).find('a.active').html() != null){
			$(this).css('background-color','#fff');
			$(this).find('a').css('color','#ed9222');
			$(this).css('border-top','1px solid #ed9222');
			$(this).css('border-left','1px solid #ed9222');
			$(this).css('border-right','1px solid #ed9222');
			$(this).height(31);
			$(this).css('position','relative');
			$(this).css('top',-4);
			$(this).find('ul').css('visibility','visible');
			$(this).children('ul').each(function(){
				$(this).find('a').css('color','#6e6e6e');
				$(this).find('a.active').css('color','#000');
				$(this).find('a').css('font-weight','bold');
			});
				
			
		}
	});	
	
	var left = 0;
	$('#nice-menu-4').children('li').each(function(){
		$(this).children('ul').each(function(){
					$(this).css('left',-left);
					$(this).children('li').each(function(){
						var width = $(this).find('a').width();
						$(this).width(width+30);
					});
		});
		left = left + $(this).width();
	});


	$('#nice-menu-4').children('li.currentpage').each(function(){
		if ($(this).find('a.active').html() != null){
			$(this).css('background-color','#fff');
			$(this).find('a').css('color','#ed9222');
			$(this).css('border-top','1px solid #ed9222');
			$(this).css('border-left','1px solid #ed9222');
			$(this).css('border-right','1px solid #ed9222');
			$(this).height(31);
			$(this).css('position','relative');
			$(this).css('top',-4);
			$(this).find('ul').css('visibility','visible');
			$(this).children('ul').each(function(){
				$(this).find('a').css('color','#6e6e6e');
				$(this).find('a.active').css('color','#000');
				$(this).find('a').css('font-weight','bold');
			});
		}
	});	
	
});
