jQuery.easing.easeOutQuart = function (x, t, b, c, d) {
    return -c * ((t=t/d-1)*t*t*t - 1) + b;
};

/* Lead Capture */
$(function() {
	$('#lead_capture').prependTo($('body'));
	
	if($('#lead_capture.open').size())
	{
		$('html, body').animate({scrollTop:0}, 'slow');

		$('#lead_capture').slideToggle();	
	}

	$('#lead, #contact_lead').live('click', function() {
		$('html, body').animate({scrollTop:0}, 'slow');

		$('#lead_capture').slideToggle();
		
		return false;
	});
	
	$('#lead_capture .close').live('click', function() {
		$('#lead_capture').slideToggle();
	});
});

/* Business Card */
$(function() {
    $('#card img:gt(0)').hide();

	var interval; 
	
	$('#card').mouseenter(function() {
		slideSwitch();
		if ( ! interval )
		{
		  	interval = window.setInterval( "slideSwitch()", 2000 );
	  	}
	});
	
	$('#card').mouseleave(function() {
		window.clearInterval(interval);
		interval = null;
		
		var integraphix = $('#card img.integraphix');
		var siblings = integraphix.siblings();
		
		$(siblings).next(integraphix).show().end().appendTo('#card').end().hide();
	});	
});

/* Portfolio */
$(function() {
	var shots = $('#more_shots');
	
	if ( $('#more_shots.has_many').size() )
	{
		// Apply Scroll Mechanism
		$('.shots_wrapper', shots).serialScroll({
		   items:'li',
		   prev:'#shots_previous',
		   next:'#shots_next',
		   start:0,
		   duration:500,
		   force:true,
		   stop:true,
		   lock:false,
		   cycle:false,
		   easing:'easeOutQuart',
		   jump: false
		});
	}
		
	function change_shot(li)
	{
		var name = $('.info .name', li).text();
		var description = $('.info .description', li).text();
		var after_url = $('.info .after .url', li).text();
		var after_alt = $('.info .after .alt',li).text();

		var before_url = $('.info .before .url', li).text();
		var before_alt = $('.info .before .alt',li).text();
					
		var container = $('<div class="shot_container"></div>');

		var img = $('<img />');
		img.attr('src', after_url);
		img.attr('alt', after_alt);

		container.append(img);

		var show = $('<a href="#" class="show">show info</a>');
		
		show.click(function() {
			$('#callout .show').fadeOut(300);
			$('#callout .content').animate({
				bottom: 0
			});
			return false;
		});
		
		container.append(show);

		var content = $('<div class="content"></div>');
		
		var wrapper = $('<div class="content_wrapper"></div>');
		
		var h3 = $('<h3></h3>').text(name);
		var hide = $('<a href="#" class="button hide">hide info</a>');

		if ( before_url )
		{
			var state = $('<a href="#" class="button redesign">before redesign</a>')
		}
		
		hide.click(function() {
			$('#callout .content').animate({
				bottom: -$('#callout .content').height()
			}, function() {
				$('#callout .show').fadeIn();
			});
			return false;
		});
		
		wrapper.append(h3);
		wrapper.append(description);
		wrapper.append(hide);
		
		if ( before_url )
		{
			wrapper.append(state);
			
			state.click(function() {
				$(this).toggleClass('selected');
									
				var old_img = $('#callout img');
			
				var new_img = $('<img />');
			
				if ( $(this).hasClass('selected') )
				{
					new_img.attr('src', before_url);
					new_img.attr('alt', before_alt);	
					$(this).text('after redesign');				
				}
				else
				{
					new_img.attr('src', after_url);
					new_img.attr('alt', after_alt);	
					$(this).text('before redesign');								
				}
				
				$(new_img).insertAfter(old_img).hide();
				new_img.fadeIn(function() {
					old_img.remove();
				});
			
				//hide.trigger('click');
				
				return false;
			});
		}
	
		content.append(wrapper);
		container.append(content);
		
		var old_img = $('#callout .shot_container');

		if ( old_img.size() )
		{
			$('.content', old_img).hide();
			
			$('#callout').append(container);
			img.hide().fadeIn(function() {
				old_img.remove();
				
				content.delay(1000).animate({
					bottom: 0
				}, 300);
			});
		}
		else
		{
			$('#callout').html(container);
			
			content.delay(1000).animate({
				bottom: 0
			}, 300);
		}
	}
	
	// Load first image
	$('.shots_wrapper li', shots).live('click', function() {
		change_shot(this);

		return false;
	});
	
	var li = $('.shots_wrapper li:first');
	
	change_shot(li);
});

/* Contact Page */
$(function() {
	if ( $('#map_canvas').length )
	{	
		var myLatlng = new google.maps.LatLng( 42.116523, -88.051704);
	    var myOptions = {
	      zoom: 16,
	      center: myLatlng,
	      mapTypeId: google.maps.MapTypeId.ROADMAP
	    }
	    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);	
	    
	    
		var marker = new google.maps.Marker({  
			position: new google.maps.LatLng(42.116523, -88.051704), 
			map: map,
			icon: '/assets/site/images/integraphix_marker.png'
		}); 

		google.maps.event.addListener(marker, 'click', function() { 
			window.open('http://maps.google.com/maps/place?hl=en&georestrict=input_srcid:91192ebab179e95f');
		});
	}
});

// Slideshow
function slideSwitch()
{
	 $('#card :first-child').next('img').show().end().appendTo('#card').end().hide();
}

// 10/2011 changes on portfolio page
 $(document).ready(function() {
				$(".project_rolldown1").hide();
				$(".view_more_projects_link1").click( function() {
					if ($(".project_rolldown1").is(":hidden")) {
							$(".project_rolldown1").slideDown(1000);
							$(".view_more_projects_link1").css('backgroundImage', 'url(http://www.integraphix.com/assets/site/images/close1.png)');
								
					  
					} else {
						$(".view_more_projects_link1").css('backgroundImage', 'url(http://www.integraphix.com/assets/site/images/expand1.png)');
						$(".project_rolldown1").slideUp(1000);   
					}
				});  
			});
			
			$(document).ready(function() {
				$(".project_rolldown2").hide();
				$(".view_more_projects_link2").click( function() {
					if ($(".project_rolldown2").is(":hidden")) {
							$(".project_rolldown2").slideDown(1000);
							$(".view_more_projects_link2").css('backgroundImage', 'url(http://www.integraphix.com/assets/site/images/close1.png)');
					  
					} else {
						$(".view_more_projects_link2").css('backgroundImage', 'url(http://www.integraphix.com/assets/site/images/expand1.png)');
						$(".project_rolldown2").slideUp(1000);   
					}
				});  
			});
			
			$(document).ready(function() {
				$(".project_rolldown3").hide();
				$(".view_more_projects_link3").click( function() {
					if ($(".project_rolldown3").is(":hidden")) {
							$(".project_rolldown3").slideDown(1000);
							$(".view_more_projects_link3").css('backgroundImage', 'url(http://www.integraphix.com/assets/site/images/close1.png)');
					  
					} else {
					   $(".view_more_projects_link3").css('backgroundImage', 'url(http://www.integraphix.com/assets/site/images/expand1.png)');
						$(".project_rolldown3").slideUp(1000);  
					}
				});  
			});

	   
$(document).ready(
				function(){
									
					$('ul#portfolio_rotating_image1').innerfade({
						speed: 1000,
						timeout: 5000,
						type: 'sequence',
						containerheight: '200px'
					});
					
					$('ul#portfolio_rotating_image2').innerfade({
						speed: 1000,
						timeout: 7000,
						type: 'sequence',
						containerheight: '200px'
					});
					
					$('ul#portfolio_rotating_image3').innerfade({
						speed: 1000,
						timeout: 6000,
						type: 'sequence',
						containerheight: '200px'
					});
					
					
					
					});
					
// 10/2011 changes for page flip	

$(document).ready(
				function(){	
		$("#page-peel").hover(function() {
		$("#page-peel img.animation_img ").stop()
			.animate({
				width: '743px', 
				height: '739px'
			}, 200); 
		$(".msg_block").stop()
			.animate({
				width: '739px', 
				height: '768px'
			}, 220); 
				
		$(".underflip-contact-form").css({'margin-top':'0', 'opacity':'1.0',});	
		$(".peel_icon").css({'opacity':'0.0',});	
		} , 
		
		
		
		function() {
		$("#page-peel img").stop() 
			.animate({
				width: '91px', 
				height: '93px'
				
			}, 220);
		$(".msg_block").stop() 
			.animate({
				height: '86px', 
				width: '86px'
			}, 190);

		$(".underflip-contact-form").css({'opacity':'0.0',});
		$(".underflip-contact-form").stop().animate({marginTop:'-800',}, 10);
		
		$(".peel_icon").css({'opacity':'1.0',});
		
			});
			});
	
	

		
					
					
					
function submitForm()
{

	
	
var name = document.getElementById("name").value;
var title = document.getElementById("title").value;
var company = document.getElementById("company").value;

var phone = document.getElementById("phone").value;
var email = document.getElementById("email").value;
var msgtxt = document.getElementById("comment").value;
var security = document.getElementById("security_question_underflip").value;


var x=document.forms["form"]["email"].value;
var atpos=x.indexOf("@");
var dotpos=x.lastIndexOf(".");

  if ( name == "" ){
	   
	
	
	 $("#description").animate({height:20, marginTop:0}); 
	 $("#description").html("Please check the name field!"); 
   }
   
   if ( title == "" ){
	   
	
	
	 $("#description").animate({height:20, marginTop:0}); 
	 $("#description").html("Please check the title field!"); 
   }
   
   
   if ( company == "" ){
	   
	
	
	 $("#description").animate({height:20, marginTop:0}); 
	 $("#description").html("Please check the company field!"); 
   }
   
   
   else if ( phone == "" ){
	   
	
	
	 $("#description").animate({height:20, marginTop:0}); 
	 $("#description").html("Please check the phone field!"); 
   }
   else if ( email == "" ){
	   
	
	
	 $("#description").animate({height:20, marginTop:0}); 
	 $("#description").html("Please check the email field!"); 
   } 
   else if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length){
	   
	
	
	 $("#description").animate({height:20, marginTop:0}); 
	 $("#description").html("Please enter a valid email address!"); 
   }
   
   
   
    else if (security != "4" || security == "" ){
	   
	
	
	 $("#description").animate({height:20, marginTop:0}); 
	 $("#description").html("Please check your answer to the Security Qestion!"); 
   }

else if(security == "4" && name != ""  && phone != ""  && email != "" && (atpos>1 || dotpos>atpos+2 || dotpos+2>x.length) ){

var xmlhttp;
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
		
		
	if(xmlhttp.responseText == "block"){   } else{
	
	
	
	window.location = "/thankyou?form=lead" 
	
	document.getElementById("error-message").innerHTML= xmlhttp.responseText; }
	
	
	
    
    }
  }
  
xmlhttp.open("POST","../../assets/admin/css/formsubmit.php",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("name="+name+"&title="+title+"&company="+company+"&phone="+phone+"&email="+email+"&comment="+msgtxt);

   } 
      
}
