$(function(){
	$(".win.gecko #containerWraper").prepend($(".win.gecko #flashHeader"));
	// $("<div id=\"snowOverlay\"></div>").appendTo("body");
	$(".ie7 body").attr({ onLoad: "window.document.mymovie.focus();" });	
});

function showMenu(){
	$('#mymovie').css( { "height":"300px" });
	$('#flashHeader').css( { "height":"300px" });
}

function hideMenu(){
	$('#mymovie').css( { "height":"97px" });
	$('#flashHeader').css( { "height":"97px" });
}

/**
 *  Fade rollover'ow
**/
$(function(){
	$(".fade").show("fast", function(){
		$(this).append("<span class=\"over\"></span>");
		$(this).children("span")
			.css({"display": "none", "opacity": "0"})
		$(this).hover(function(){
			$(this).children("span")
				.stop()
				.css({"display": "none", "opacity": "1"})
				.fadeIn("fast");
		},function(){
			$(this).children("span")
				.stop()
				.fadeOut("slow");
		});
	});
});


/**
 *  Lightbox
**/
// $(function(){
// 	$("#galleryContainer a").lightBox({
// 		overlayOpacity: 0.0,
// 		containerBorderSize: 10,
// 		txtImage: "ZdjÄcie",
// 		txtOf: "z"
// 	});
// });

$(function(){
	try
	{
		$("a.curiosityThumbnail").lightBox({
			overlayOpacity: 0.0,
			containerBorderSize: 10,
			txtImage: "Zdjęcie",
			txtOf: "z"
		});
	}
	catch(e)
	{
		//console.log(e);		
	}
		
	});

/**
 *  WybĂłr karty w #2 kroku rejestracji
**/
$(function(){
	$('.cardContainer').click( function(){
		$('.cardContainer  label').removeClass('cardSelected').addClass('cardNotSelected');
		$(this).children('label').removeClass('cardNotSelected').addClass('cardSelected');
	});
});

$(function(){
	$('#scrollContainer').click( function(){
		$('#scrollItems').animate( { left:"-530px" }, 600);
	});
});


$(function(){
	$(".formGroupWraper div").show("fast", function(){
		$(this).children("span")
			.css({"display": "none", "opacity": "0"})
		$(this).hover(function(){
			$(this).children("span")
				.stop()
				.css({"display": "none", "opacity": "1"})
				.fadeIn("fast");
		},function(){
			$(this).children("span")
				.stop()
				.fadeOut("slow");
		});
	});
});


// ======================================
// = jQ functions ran at document.ready =
// ======================================


/**
 *  ZaokrÄglanie naroznikow zdjec
**/

function roundedCorners(){
	$(".roundedCorners").css({marginBottom: 0})
		.wrap("<div class=\"roundedCornersWraper\"></div>");
	$(".roundedCornersWraper").css({width: $(".roundedCorners").width()})
		.append("<div class=\"roundCornerTL\"></div>")
		.append("<div class=\"roundCornerTR\"></div>")
		.append("<div class=\"roundCornerBL\"></div>")
		.append("<div class=\"roundCornerBR\"></div>");
}


function fixIE7Headers(){
	$(".ie7 h3").replaceWith("<pre class=\"h3\">" + $(this).text() + "</pre>");
}

//To zostalo dadane
$(document).ready(function(){
	if(window.location.href.indexOf('remindPasswordAction.do') != -1)
	{
		$('#content').html('<span id="restorePasswordTextIE"></span>');
		
		//$('#content').find('h3.typeface-js:first').css('display','none')
		//			.parent().prepend('<span id="restorePasswordTextIE"></span>');		
	}
});
//To zostalo dadane

$(document).ready(function(){
	
 
	// stopka w toyota more
	 var cBodyAttr = $('body').attr('id');
                if (cBodyAttr == 'mainPage'){
                    $('#footer').remove();
                    $('body').append('<div id="footer" style="height:140px"><div style="font-size:12px; padding:40px 60px; color:#666"><b>Biuro obsługi programu:</b>      infolinia <b style="font-size:13px; color:#CE192A;">0801 20 20 20</b> lub <b style="font-size:13px; color:#CE192A;">+48 22 574 04 35</b>;      e-mail <a href="mailto:info@toyotamore.pl" style="text-decoration:none;"> <b style="font-size:13px; color:#CE192A;">info@toyotamore.pl</b></a></div><span style="top:80px;">© Copyright 2009 TMPL TBP | Polityka prywatności</span> <a id="toyotaBank" style="top:78px;" href="http://www.toyotabank.pl">Toyota Bank</a> <a style="top:63px;" id="toyotaPl" href="http://www.toyota.pl">Toyota</a></div>');
                }
	
	//console.log('test');
	$('form#formJakosc').submit(function(){
		//console.log('test1', $(this).find('input[name="_fld_zadowolenie"]:checked').length);
		if($(this).find('input[name="_fld_zadowolenie"]:checked').length == 0)
		{
			alert('Musisz zaznaczyć');
			return false;			
		}
		//console.log('test1', $(this).find('input[name="_fld_polecenie"]:checked').length);
		if($(this).find('input[name="_fld_polecenie"]:checked').length == 0)
		{
			alert('Musisz zaznaczyć');
			return false;			
		}
		return true;
	});	
	
	$('#pointsListContainer').append('<ul id="list"></ul>');
	$('#pointsListContainer li').each(function(){
	 $(this).parent().addClass('removeIt');
	 var newPoinsList;
	 var newPoinsListCurrent = $(this).html();
	 var currentID = $(this).attr('id');
	 var prepareVar = '<li id="'+currentID+'">'+newPoinsListCurrent+'</li>';
	 $('#pointsListContainer ul#list').append(prepareVar);
	 if (currentID=='points5'){
	  $('#pointsListContainer ul#list').append('<li id="points6"><strong>100pkt</strong> za każde 100 punktów zebranych w programie Shell Smart</li>');
	 }
	 $(this).remove();
	});
	$('#pointsListContainer ul.removeIt').remove();
	
	var flashvars = {};
	var params = {};
	var attributes = {};
	var so = new SWFObject("http://www.toyotamore.pl/tlp-public-web/flash/360x250_lato_BIS.swf", "opony", "360", "250", "8", false, flashvars, params, attributes);
	so.write("ciekawostkiContainer");
	
	// TOYOTA NEWS
	// $("#mainPage .sidebar").append("<a href=\"http://www.toyotamore.pl/tlp-public-web/pagesAction.do?name=ToyotaNews\" id=\"toyotaNews\"><h3>Toyota News</h3><p>Zapoznaj się z najnowszym numerem biuletynu.</p></a>");
	 
 	var div = $('<div>').css({"margin-left": "30px", "height": "20px", "color": "#8A8A8A", "font-weight": "bold", "font-size": "15px"}).text('Sprawdź najnowsze wydania biuletynów:');
 	var newEl = $('<div>').attr('id', 'toyotaNews').css('background', '#EFEFEF').html('<p><a href="http://www.toyotamore.pl/tlp-public-web/pagesAction.do?name=ToyotaNews" class="toyotaNewsLink" target="_blank">&raquo; Toyota News (pdf)</a><br /><a href="http://newsletter.toyotamore.pl/" class="toyotaNewsLink" target="_blank">&raquo; Toyota More (www)</a><br /></p>');
 	newEl.find('.toyotaNewsLink').css('color', '#8A8A8A');
	newEl.prepend(div);
 	$("#mainPage .sidebar").append(newEl);
	
	roundedCorners();
	fixIE7Headers();
});


/**
 *  Fixing PNGs in IE6/7
**/
DD_belatedPNG.fix('#footer');
DD_belatedPNG.fix('.imageOverlay');
DD_belatedPNG.fix('.roundCornerTL');
DD_belatedPNG.fix('.roundCornerTR');
DD_belatedPNG.fix('.roundCornerBL');
DD_belatedPNG.fix('.roundCornerBR');
DD_belatedPNG.fix('.hoverRight');
DD_belatedPNG.fix('#scrollOverlay');
DD_belatedPNG.fix('#toyotaNewsCoverOverlay');
DD_belatedPNG.fix('#ciekawostkiHeader');


/**
 *  Sonda Fixing others text field
**/
function disableField(value)
  {
  if (value == 1)
  {
   document.getElementById("textfield").disabled=true
   }
   else
   {
   document.getElementById("textfield").disabled=false
   }
  };

/**
 *  Sonda text field validation
**/  
  function isAlphabet(elem, helperMsg){
	var alphaExp = /^[a-zA-Z]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
	}
		return false;
};
