/**
 * @author Aram
 */			
			/*************************************************
			* 
			* Modal Window
			* 
			************************************************/
			function launchModalWindow(id, page){
					
					//Get the window height and width
					var winH = jQuery(window).height();
					var winW = jQuery(window).width();
				
					//Get the screen height and width
					var maskWidth = 4000;
					var maskHeight = jQuery(document).height(); 
					
					jQuery('#mask').css({'left': 0});
					
					if(page == 'portfolio'){
						jQuery(id).css('left', (winW/2-jQuery(id).width()/2)+ 1920);
					}			
					else{
						jQuery(id).css('left', (winW/2-jQuery(id).width()/2));
					}			
					//Set height and width to mask to fill up the whole screen
					jQuery('#mask').css({'width':maskWidth,'height':maskHeight, 'opacity':0.3});
					
					//transition effect
					jQuery('#mask').fadeIn('slow');	
					
			              
					//Set the popup window to center
					jQuery(id).css('top',  (winH/2-jQuery(id).height()/2)+ jQuery(window).scrollTop());
					//transition effect
					jQuery(id).fadeIn(500); 

			}	
			function closeModalWindow(){
					jQuery('.window').fadeOut('fast');
					jQuery('#mask').fadeOut('fast');
					return false;
			}
			/*****************************
			 * 
			 * FORMS
			 * 
			 *****************************/ 
			//Hides form lables and puts the label value as the field value
			function hideFormLabels(form) {
				jQuery(form).find("label.left").each(function(){
					text = jQuery(this).html();
					inputID = jQuery(this).attr('for');

						jQuery('input#' + inputID).val(text);	
						jQuery('textarea#' + inputID).val(text);
						jQuery(this).hide();
				});
			}
			//Clears fields on click
			function clearField(form) {
					jQuery(form).find("input.text, textarea").each(function(){	
						this.defaultValue = this.value;
						jQuery(this).click(function(){
							if(this.value == this.defaultValue){
								jQuery(this).val("");
							}
						});
					});
			}

			/*****************************
			 * 
			 * UI Enhancement
			 * 
			 *****************************/ 
			 
			// Make block clickable
			function clickBlock(block, link){

					jQuery(block).click(function() {
					  window.open(jQuery(this).find(link).attr("href"));
					  return false;
					});
					jQuery(block).hover(  
						function() {  
					     jQuery(this).addClass("hover");   
						},  
						function() {  
					     jQuery(this).removeClass("hover");  
						}  
					);		
			}
			// Make block clickable (modal
			function clickBlockModal(block, link, page){
					jQuery(link).unbind('click');
					jQuery(block).click(function() {			
					  launchModalWindow(jQuery(this).find(link).attr("href"), page);
					  return false;
					});
					jQuery(block).hover(  
						function() {  
					     jQuery(this).addClass("hover");   
						},  
						function() {  
					     jQuery(this).removeClass("hover");  
						}  
					);		
			}

					
			/*****************************
			 * 
			 * Slides
			 * 
			 *****************************/ 
			
			function slideSwitch(){
				
				current = jQuery("#homeBanner div.current")[0];
				
				if (current.id == "slide1") {
					jQuery("#slide2").addClass("top").fadeIn("slow", function(){
						jQuery("#slide1").removeClass("current").hide();
						jQuery("#slide2").addClass("current").removeClass("top");
						
					});
				}
				if (current.id == "slide2") {
					jQuery("#slide3").addClass("top").fadeIn("slow", function(){
						jQuery("#slide2").removeClass("current").hide();
						jQuery("#slide3").addClass("current").removeClass("top");
					});
				}
				else if (current.id == "slide3") {
					jQuery("#slide4").addClass("top").fadeIn("slow", function(){
						jQuery("#slide3").removeClass("current").hide();
						jQuery("#slide4").addClass("current").removeClass("top");
					});
				}
				else if (current.id == "slide4") {
					jQuery("#slide1").addClass("top").fadeIn("slow", function(){
						jQuery("#slide4").removeClass("current").hide();
						jQuery("#slide1").addClass("current").removeClass("top");
					});
				}
			}	
			/* ***************************
			 * 
			 * AJAX Form Submissions
			 * 
			 ***************************/			
			function SendContactForm(form) {
			
					
				var name = jQuery("input#Form_" + form + "_" + form + "Name").val();
			
				var email = jQuery("input#Form_" + form + "_" + form + "Email").val();
			
				var message = jQuery("textarea#Form_" + form + "_" + form + "Comments").val();
					
				var dataString = 'name='+ name + '&email=' + email + '&message=' + message;
				
				var baseURL = window.location;
				
				//alert(dataString);
				jQuery.ajax({
			      type: "POST",
			      url: baseURL + "home/SendForm",
				  data: dataString,
			      success: function() {
			        jQuery('#' + form + 'Container').html("<div id='message'></div>");
			        jQuery('#message').html("<h2>Message sent!</h2>")
			        .append("<p>We will get back to you as soon as we can, usually the same day.</p>")
			        .hide()
			        .fadeIn(1500, function() {
			          jQuery('#message').append("<img id='checkmark' src='images/check.png' />");
			        });
			      }
			     });
		
			    return false;
			
			}				
			function SendQuoteForm() {

			
				var name = jQuery("input#Form_QuoteForm_QuoteFormName").val();
			
				var email = jQuery("input#Form_QuoteForm_QuoteFormEmail").val();
				
				var telephone = jQuery("input#Form_QuoteForm_Telephone").val();
				
				var current = jQuery("input#Form_QuoteForm_CurrentSite").val();
				
				var pages = jQuery("select#Form_QuoteForm_Pages").val();
				
				var budget = jQuery("select#Form_QuoteForm_Budget").val();
				
				var design = jQuery("input#Form_QuoteForm_Design").is(':checked');
				
				var development = jQuery("input#Form_QuoteForm_Development").is(':checked');
				
				var animation = jQuery("input#Form_QuoteForm_Animation").is(':checked');
				
				var cms = jQuery("input#Form_QuoteForm_CMS").is(':checked');
			
				var message = jQuery("textarea#Form_QuoteForm_Description").val();
					
				var dataString = 'name='+ name + '&email=' + email + '&telephone='+ telephone + '&current='+ current + 
								'&pages='+ pages + '&budget='+ budget + '&design='+ design  + 
								'&development='+ development + '&animation='+ animation + '&cms='+ cms + '&message=' + message;
			
				var baseURL = window.location;
			
				//alert(dataString);
				jQuery.ajax({
			      type: "POST",
			      url: baseURL + "home/SendQuoteForm",
				  data: dataString,
			      success: function() {
			        jQuery('#QuoteFormContainer').html("<div id='message'></div>");
			        jQuery('#message').html("<h2>Quote request sent!</h2>")
			        .append("<p>We will get back to you as soon as we can, usually the same day.</p>")
			        .hide()
			        .fadeIn(1500, function() {
			          jQuery('#message');
			        });
			      }
			     });
			
			    return false;
			
			}
/*****************************
			 * 
			 * Document Ready
			 * 
 *****************************/
			jQuery(document).ready(function() {												
					//modal window for home links
					jQuery('#showcase a.modal img').click(function(e) {
						e.preventDefault();
						var id = jQuery(this).parent().attr('href');		
						launchModalWindow(id, 'home');			
					});		
					//modal window for currently in development links
					jQuery('#portfolioBlock .baseBlock a.modal img').click(function(e) {
						e.preventDefault();
						var id = jQuery(this).parent().attr('href');		
						launchModalWindow(id, 'portfolio');			
					});			
					//close button
					jQuery('.window .close').click(function (e) {
						e.preventDefault();
						closeModalWindow();
					});				
					//mask is clicked
					jQuery('#mask').click(function () {
						closeModalWindow();
					});		
									
					hideFormLabels("#Form_ContactForm");
					clearField("#Form_ContactForm");
					hideFormLabels("#Form_HomeForm");
					clearField("#Form_HomeForm");	
					hideFormLabels("#Form_QuoteForm");
					clearField("#Form_QuoteForm");	
				
					
					/**
					 * Validation
					 */
					
						jQuery("#Form_HomeForm").validate({
							rules: {
								HomeFormName: "required",
								HomeFormEmail: {
									required: true,
									email: true
								},
								HomeFormComments: {
									required: true,
									minlength: 10
								}
							},
							messages: {
								HomeFormName: "Please enter your name",
								HomeFormEmail: "Please enter a valid email address",
								HomeFormComments: "Please enter your comments"
							},
							submitHandler: function(){
								SendContactForm("HomeForm");
							}
						});
						jQuery("#Form_QuoteForm").validate({
							rules: {
								QuoteFormName: "required",
								QuoteFormEmail: {
									required: true,
									email: true
								},
								Description: {
									required: true,
									minlength: 100
								}
							},
							messages: {
								Name: "Please enter your name",
								Email: "Please enter a valid email address",
								Comments: "Please enter your comments (min 40 chars)"
							},
							submitHandler: function(){
								SendQuoteForm();
							}
						});
						jQuery("#Form_ContactForm").validate({
							rules:{
								ContactFormName: "required",
								ContactFormEmail: {
									required: true,
									email: true
								},
								ContactFormComments: {
									required: true,
									minlength: 10
								}
							},
							messages: {
								ContactFormName: "Please enter your name",
								ContactFormEmail: "Please enter a valid email address",
								ContactFormComments: "Please enter your comments"
							},
							submitHandler: function(){
								SendContactForm("ContactForm");
							}
						});
					//If were in IE6 it means were going to be on a single page so no offset needed, so we pass home as the page argument
					if ((jQuery.browser.msie && jQuery.browser.version == "6.0") || window.location.href == 'http://www.aabweb.co.uk/portfolio') {
						clickBlockModal("#portfolioList div.preview", "a.modal", "home");
					} else{
						clickBlockModal("#portfolioList div.preview", "a.modal", "portfolio");						
					}
					/**
					 * Insert flash
					 */
					jQuery('#flashMovie').html('<embed height="170" width="315" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" loop="true" menu="false" quality="high" wmode="opaque" src="assets/Uploads/AAB_anim_example.swf"/>');
													
			});