jQuery.noConflict();

jQuery(document).ready(function(){
	Sizes = new Array(0);
	jQuery(".inner,.innernobackground").each(function(){
		height = jQuery(this).height();
		Sizes.push(height);
	});
	//do this after 1 second, just to make sure that image sizes are loaded
	res = function(){
		jQuery(".inner,.innernobackground").height(Math.max.apply( Math, Sizes )).css({marginBottom:20,paddingBottom:20});
	}
	setTimeout("res()",1000);



	showrightbar = function(){
		jQuery(".rightbar").fadeIn();
	}
	//setTimeout("showrightbar();",500);
	
	a = jQuery(".rightbar").html();
	b = jQuery(".rightbar").height();
	c = (b/2) - 10;
	jQuery(".rightbar").css({height:b}).empty().append("<div class='bb'><img src='img/ajax-loader.gif' style='margin-top:"+c+"px;margin-left:60px;'></div>");
	
	injectcontent = function(a){
		jQuery(".rightbar .bb").empty().hide();
		jQuery(".rightbar .bb").append(a).fadeIn();
	}
	
	setTimeout("injectcontent(a);",1000);
	
	
	
	show_box_after_callback = function(){
		if(jQuery.browser.msie){
			h = jQuery("object").heigth();
			jQuery("object").after("<div class='rmove' style='height:"+h+"px'></div>");
			jQuery("object").hide();
		}
		// after submission of form show the box again saying thank you.
		html = "<div class='overlay'></div><div class='box'></div>";
		
		boxhtml = "<h1>Thank you. Your enquiry have been submitted.</h1>";		
		
		jQuery('body').append(html);
		jQuery(".overlay").css({
			top:0,
			left:0,
			width:'100%',
			height:'100%',
			position:'fixed',
			backgroundColor:'black',
			opacity:0.8
		}).hide().fadeIn().click(function(){
			jQuery(this).fadeOut(function(){jQuery(this).remove()});
			jQuery(".box").fadeOut(function(){jQuery(this).remove()});
		});
		
		jQuery(".box").css({
			top:'50%',
			left:'50%',
			width:390,
			height:16,
			position:'absolute',
			backgroundColor:'white',
			marginLeft:'-195px',
			marginTop:'-8px',
			'-moz-border-radius':10,
			'-webkit-border-radius':10,
			'-webkit-box-shadow':'5px 5px 5px rgba(0, 0, 0, 0.5)',
			'-moz-box-shadow':'5px 5px 5px rgba(0, 0, 0, 0.5)'
		}).hide().append(boxhtml).fadeIn();
		
		fadeoutbox = function(){
			jQuery(".overlay").fadeOut(function(){jQuery(this).remove()});
			jQuery(".box").fadeOut(function(){jQuery(this).remove()});
			if(jQuery.browser.msie){
				jQuery("div.rmove").remove();
				jQuery("object").show();
			};
		};
		
		setTimeout("fadeoutbox();", 1000);
		
	};
	
	jQuery(".submit_your_plans").click(function(){
		if(jQuery.browser.msie){
			h = jQuery("object").height();
			jQuery("object").after("<div class='rmove' style='height:"+h+"px'></div>");
			jQuery("object").hide();
		};
		this_page = document.location;
		
		html = "<div class='overlay'></div><div class='box'></div>";
		
		boxhtml = "<h1>Express Enquiry</h1><form class='form' action='submit_plans.php' method='post' enctype='form-data/multipart'><input type='hidden' name='ref' value='"+this_page+"'><table><tr><td>Company Name</td><td><input type='text' name='company_name'></td></tr><tr><td>Project Details</td><td><input type='text' name='project_details'></td></tr><tr><td>Email</td><td><input type='text' name='email'></td></tr><tr><td>Telephone Number</td><td><input type='text' name='telephone_number'></td></tr><tr><td>Best time to call</td><td><input type='text' name='best_time_to_call'></td></tr><tr><td colspan=2><button type='submit' class='do_send_form'>Send Enquiry</button><button class='close_box'>Cancel</button></td></tr></table></form>";		
		
		jQuery('body').append(html);
		jQuery(".overlay").css({
			top:0,
			left:0,
			width:'100%',
			height:'100%',
			position:'fixed',
			backgroundColor:'black',
			opacity:0.8
		}).hide().fadeIn().click(function(){
			jQuery(this).fadeOut(function(){jQuery(this).remove()});
			jQuery(".box").fadeOut(function(){jQuery(this).remove()});
			if(jQuery.browser.msie){
				jQuery("div.rmove").remove();
				jQuery("object").show();
			}
		});
		
		jQuery(".close_box").live("click",function(){
			jQuery(".overlay").fadeOut(function(){jQuery(this).remove()});
			jQuery(".box").fadeOut(function(){jQuery(this).remove()});
			if(jQuery.browser.msie){
				jQuery("div.rmove").remove();
				jQuery("object").show();
			}
			return false;
		});
		
		jQuery(".form").live("submit",function(){
			
			company_name = jQuery(".form input[name='company_name']").val();
			project_details = jQuery(".form input[name='project_details']").val();
			email = jQuery(".form input[name='email']").val();
			telephone_number = jQuery(".form input[name='telephone_number']").val();
			best_time_to_call = jQuery(".form input[name='best_time_to_call']").val();
			pdf_plans = jQuery(".form input[name='pdf_plans']").val();
						
			pdf_plansparts = pdf_plans.split(".").reverse();
			ext = pdf_plansparts[0];

			if(company_name == ""){
				alert("The 'company name' field is compulsory");
			}else if(project_details == ""){
				alert("The 'project details' field is compulsory");
			}else if(email == ""){
				alert("The 'email' field is compulsory");
			}else if(telephone_number == ""){
				alert("The 'telephone number' field is compulsory");
			}else if(best_time_to_call == ""){
				alert("The 'best time to call' field is compulsory");
			}else if(ext != "pdf"){
				alert("The 'PDF Plans' file must be a PDF");
			}else{
				return true;
			};
			
			return false;
		});
		
		
		
		jQuery(".box").css({
			top:'50%',
			left:'50%',
			height:180,
			position:'absolute',
			backgroundColor:'white',
			marginTop:'-120px',
			'-moz-border-radius':10,
			'-webkit-border-radius':10,
			'-webkit-box-shadow':'5px 5px 5px rgba(0, 0, 0, 0.5)',
			'-moz-box-shadow':'5px 5px 5px rgba(0, 0, 0, 0.5)'
		}).hide().append(boxhtml).css({marginLeft:'-'+parseInt( parseInt(jQuery(".box").width()) / 2 )+'px'}).fadeIn();
		if(jQuery.browser.msie){
			jQuery(".box").css({
				height:200
			});
		};
		
		return false;
		
	});
	
	
});