function init_gallery()

	{

		var images = new Array();

		$('.gallery img').each(function(i){

									var imagesrc = $(this).attr('src');

									var imagename = imagesrc.replace("sample","large_sample");

									images[i] = new Image();

									images[i].src = imagename;

									});

		$('.gallery li').each(function(i){

										$(this).hover(function()

											{									

												var captiontext = $(this).children('img').attr('alt');

												$('#preview p').text(captiontext);

												$('#preview').show();

												

												$().mousemove(function(mouse)

															  {

																  var x = getViewPort();

																  var y = getScroll();

																  if (mouse.pageY+images[i].height-150 < x + y - 80) 

																  	{

																		$('#preview').css({top:mouse.pageY-150, left:mouse.pageX-60-images[i].width});

																	} else

																	{

																		$('#preview').css({top:y+x-images[i].height-80, left:mouse.pageX-60-images[i].width});	

																	}

															  }); 

												$('#preview').css({width:images[i].width});

												$('#preview img').attr('src', images[i].src);									

											}, function()

											{

												$('#preview').hide();	

											});

									   });

	}

function getViewPort()

	{

		var viewportheight = 0;

		if (typeof window.innerWidth != 'undefined')

		 {

			  viewportheight = window.innerHeight

		 } else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth !='undefined' && document.documentElement.clientWidth != 0)

		 {

			   viewportheight = document.documentElement.clientHeight

		 }else

		 {

			   viewportheight = document.getElementsByTagName('body')[0].clientHeight

		 }

		 return viewportheight;

	}

function getScroll() 

	{

		  var scrollheight = 0;

		  if( typeof( window.pageYOffset ) == 'number' ) {

				scrollheight = window.pageYOffset;

		  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {

				scrollheight = document.body.scrollTop;

		  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) 

		  {

				scrollheight = document.documentElement.scrollTop;

		  }

		  return scrollheight;

	}

	

function init_quote_rotate()

	{

		var howmayQuotes = $(".quote").size();

		$(".quote").hide();

    	var ranNum= Math.floor(Math.random() * howmayQuotes);

		$(".quote:nth("+ ranNum +")").show();

	}

function validate_form()

	{

		$('button.submit').click( function ()

			 {

				var sw = 0;

				if (!$('#chxfirstname').val()) 

						{ 

							sw=1;

							$('#chxfirstname').addClass('error');

						}

				if (!$('#chxlastname').val())

						{ 

							sw=1;

							$('#chxlastname').addClass('error');

						}

				if (!($('#chxphone').val() || $('#chxemail').val())) 

						{

								sw=1;

								$('#chxphone').addClass('error');

								$('#chxemail').addClass('error');

						}

				if (!sw)

					{

						$('#form').remove();

						$('p.form-mess').text('A Pyrotecnico representative will contact you within one business day regarding your request.').removeClass('error');;

						$('.titl-contactuswe').removeClass('titl-sorrybutthere').addClass('titl-thankyou');

					} else

					{

						$('p.form-mess').text('Please provide all the required fields').addClass('error');

						$('.titl-contactuswe').addClass('titl-sorrybutthere');

						sw = 0;

					}

			 	return false;

			 });

	}



jQuery(function($) {

   init_gallery();

   init_quote_rotate();

   validate_form();

 });