jQuery(document).ready(function() {
		 var arrHostess = new Array();
		 var i = 1;
		 var imgCount = 3;
		 var imgCountEvent = 3;
		 for(i ; i<= imgCount ; i++)
		 {
		      var img = new Image();
		      img.src = '/upload/fotoemotion/background/bgfoto_' + i + '.jpg';
		      arrHostess.push(img);
		 };

		 var m = Math.floor(Math.random() * arrHostess.length);
		 if (document.location.href.indexOf('/index.xml') == -1 && $('.mainPage').length == 0)
		 {
			 $(".body_0 #container").css('background', 'url('+ arrHostess[m].src+') no-repeat');
			 $(".body_0 #container").attr('style', 'background: url('+ arrHostess[m].src+') no-repeat');
		 }

		 var arrEvents = new Array();

		 i = 1;
		 for(i ; i<= imgCountEvent ; i++)
		 {
		      var img = new Image();
		      img.src = '/upload/background/bgeventsmodel_' + i + '.jpg';
		      arrEvents.push(img);
		 };
		 var e = Math.floor(Math.random() * arrEvents.length);
		 $(".body_1 .mainPage").css('background','url('+  arrEvents[e].src + ') no-repeat');
		 $(".body_1 .mainPage").attr('style', 'background: url('+  arrEvents[e].src + ') no-repeat');

/*
    $(document).bind("contextmenu",function(e){
        return false;
       }); 
*/
    $("#photo").inputfile();
    $("#photo2").inputfile();
    $("#photo3").inputfile();
    $(".select").selectbox();

    $('#container a[rel=lightbox]').lightBox();

	var config = {
	    sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)
	    interval: 150, // number = milliseconds for onMouseOver polling interval
	    over: function() {
	    			$(this).children(".subMenu").fadeIn('slow') },
	    timeout: 150, // number = milliseconds delay before onMouseOut
	    out: function() {
	    	 		$(this).children(".subMenu").fadeOut('slow') }
	};
	$("#menu li").hoverIntent( config );
	$('#container[class!=model] #text').pager('p',{perPage: 1});
	$('.dokonania').pager('div',{hideNav: 'true'});
	$('.gallery').pager('div.gallery_page', {hideNav: 'true' , perPage: 1 });
	$('.model').pager('div.gallery_page',{hideNav: 'false', perPage: 1});
	$("#nav").pngFix();
	$(".index").pngFix();

	var iloscFrame = $(".frame").length;
	if (iloscFrame < 4){
		$(".leftArrow").css("display","none");
		$(".rightArrow").css("display","none");
	}

	jQuery.validator.addMethod("imie", function(imie_nazwisko, element) {
		imie_nazwisko = imie_nazwisko.replace(/\s+/g, " ");
		return this.optional(element) || (imie_nazwisko != 'imie nazwisko' && imie_nazwisko != 'name surname' &&
			imie_nazwisko.match(/^\s?[a-zA-Z]+\s+[a-zA-Z]+$/));
	}, "Podaj imię i nazwisko");

	jQuery.validator.addMethod("datePL", function(date_PL, element) {
		date_PL = date_PL.replace(/\s+/g, "");
		return this.optional(element) || date_PL.length > 9 &&
			date_PL.match(/^(0[1-9]|[12][0-9]|3[01])[-](0[1-9]|1[012])[-](19|20)\d\d$/);
	}, "Podaj poprawną datę RRRR-MM-DD");

	jQuery.validator.addMethod("noDigits", function(no_Digits, element) {
		no_Digits = no_Digits.replace(/\s+/g, "");
		return this.optional(element) ||
			no_Digits.match(/^[a-zA-Z]+$/);
	}, "Wymagane tylko litery");

	if($('#container').hasClass('message')){
		var validator_message = $('#message_form').validate({
			rules:{
				from:{
					required:true,
					email:true
				},
				message:{
					required:true
				}
			},
			messages:{
				from :{
					required:" ",
					email:" "
				},
				message:{
					required:" "
				}
			},
			invalidHandler: function() {
				var errors = validator_message.numberOfInvalids();
				if(errors == 1){
					alert("Popraw "+ errors+" wymagane pole");
				}else{
					alert("Popraw "+ errors+" wymagane pola");
				}
			}
			});

	};
	$("#name").click(
			function(){
				if($(this).val()=="imie nazwisko" || $(this).val()=="name surname"){
					$(this).val(" ");
					}
				}
		);
	$("#date").click(
			function(){
				if($(this).val()=="dd-mm-rrrr"){
					$(this).val(" ");
					}
				}
		);
	$("img").mouseover(
		function(){
			var fileName =$(this).attr('src');
			if(fileName!='' && fileName!='bw_'){
				var source = fileName.slice(0 , fileName.lastIndexOf("/")+1);
				var fileColor = (fileName.slice(fileName.lastIndexOf("/")+1)).slice(3);
				var color = source + fileColor;
				$(this).attr('src',color);
			}}
	).mouseout(
		function() {
			var fileName =$(this).attr('src');
			if(fileName!='' && fileName!='bw_'){
				var source = fileName.slice(0 , fileName.lastIndexOf("/")+1);
				var fileBlack = 'bw_'+fileName.slice(fileName.lastIndexOf("/")+1);
				var black = source + fileBlack;
				$(this).attr('src',black);
			}}
		)
	});

$(window).load( function() {
	var msie6 = $.browser.msie && parseInt($.browser.version) < 7
	$("#menu > li").each( function() {
		var a = $(this).children("a:first()");
		if (!a)
			return;

		var w = $(a).width();
		a.css('text-indent', '-9999px');
//		a.attr('text-indent', '-9999px');
		var text = a.text().toLowerCase();
		if (!msie6){
			if(a.parent().hasClass('active'))
			{
				a.css('background', 'url("/photoemotion/svg/top_menu_active.svg?format=png&text=' + text +'&height=20") no-repeat center 0px;');
				a.attr('style', 'background: url("/photoemotion/svg/top_menu_active.svg?format=png&text=' + text +'&height=20") no-repeat center 0px; text-indent: -9999px; width: ' + w  + 'px');
			}
			else
			{
				a.css('background', 'url("/photoemotion/svg/top_menu.svg?format=png&text=' + text +'&height=20") no-repeat center 0px;');
				a.attr('style', 'background: url("/photoemotion/svg/top_menu.svg?format=png&text=' + text +'&height=20") no-repeat center 0px;  text-indent: -9999px; width: ' + w  + 'px');
			}
		}else{
			if(a.parent().hasClass('active'))
				a.css('filter', 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="/photoemotion/svg/top_menu_active.svg?format=png&text=' + text +'&height=20", sizingMethod=\'crop\')');
			else
				a.css('filter', 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="/photoemotion/svg/top_menu.svg?format=png&text=' + text +'&height=20", sizingMethod=\'crop\')');
		}
		a.width(w);
	});

	$(".subMenu > li").each( function() {
		var a = $(this).children("a:first()");
		if (!a)
			return;

		a.css('display', 'block');
		a.css('text-indent', '-9999px');
		var text = a.text().toLowerCase();
		if (!msie6)
			a.css('background', 'url("/photoemotion/svg/top_sub_menu.svg?format=png&text=' + text +'&height=20") no-repeat left 0px');
		else
			a.css('filter', 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="/photoemotion/svg/top_sub_menu.svg?format=png&text=' + text +'&height=20", sizingMethod=\'crop\')');
		a.width(150);
	});
		var hos = $("#hostesses");
		if (!hos)
			return;
		var w = $(hos).width();
		hos.css('text-indent', '-9999px');
		var text = hos.text();
		if (!msie6)
			hos.css('background', 'url("/svg/header.svg?format=png&text=' + text +'&height=20") no-repeat center 0px');
		else
			hos.css('filter', 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="/svg/header.svg?format=png&text=' + text +'&height=20", sizingMethod=\'crop\')');
		hos.width(w);

		var event = $("#events");
		if (!event)
			return;
		var w = $(event).width();
		event.css('text-indent', '-9999px');
		var text = event.text();
		if (!msie6)
			event.css('background', 'url("/svg/events.svg?format=png&text=' + text +'&height=20") no-repeat center 0px');
		else
			event.css('filter', 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="/svg/events.svg?format=png&text=' + text +'&height=20", sizingMethod=\'crop\')');
		event.width(w);

		$("#footer > a").each( function() {
			var a = $(this);
			if (!a)
				return;
			if(!(a.hasClass("pl")) && !(a.hasClass("en"))){
				var w = $(a).width();
				a.css('display', 'block');
				a.css('text-indent', '-9999px');
				var text = a.text().toLowerCase();
				if (!msie6)
					a.css('background', 'url("/svg/footer.svg?format=png&text=' + text +'&height=15") no-repeat left 0px');
				else
					a.css('filter', 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="/svg/footer.svg?format=png&text=' + text +'&height=15", sizingMethod=\'crop\')');
				a.width(w+30);
			}
		});

});

