$(document).ready(function() {
	$(window).resize(function() { fn.checkElement('body'); });
	fn.checkElement('body');
	$('.scrolltext').find('img').show().end().cycle({ fx: 'fade'	});
	$('#imagehome').cycle({ fx: 'fade'});
	$('#container').after('<div id="nav" class="nav">').cycle({
		fx:     'fade',
		speed:  'fast',
		timeout: 3000,
		pager:  '#nav',
		pauseOnPagerHover: 1
	});	
});

var fn = {
	base: "http://www.archengine.com.au/",
	cookie_name: "isLarge",
	opt: { path:'/', expires:10 },
	
	loadMap: function(obj) {		
		if($('#googlemap').length < 1) $('.imagebrand').prepend('<iframe id="googlemap" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com.au/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=13+Kirketon+Road,+Darlinghurst&amp;sll=-25.335448,135.745076&amp;sspn=44.678017,56.513672&amp;ie=UTF8&amp;ll=-33.865142,151.225262&amp;spn=0.01386,0.027874&amp;z=14&amp;iwloc=A&amp;output=embed"></iframe>');
		$('.imagebrand img').fadeOut('fast', function() { $('#googlemap').fadeIn('slow') } );		
	},
	
	isLarge: function() {
		if ($.cookie(fn.cookie_name) == null) {
			// Set the cookie and return the size.
			return fn.checkElement('body');
		} else {
			// Return the size previously cookified.
			return ($.cookie(fn.cookie_name) == false);
		}
	},

	checkElement: function (obj) {
		if($(window).width() < 1060 ) { 
			//$(obj).addClass('small');
			$.cookie(fn.cookie_name, false, fn.opt);
			return false;
		}
		else { 
			//$(obj).removeClass('small');
			$.cookie(fn.cookie_name, true, fn.opt);
		    	return true;
		}
 	},
	
	submit: function(obj) {
		var error = false;
		var msg = '';
		$(obj).attr('style', 'opacity:0.2').find('.verify').each(function() { if($(this).val() == '') { error = true; msg = msg + ' - ' + $(this).attr('title')+"\n";  } } );
		if(error) {
			alert("Could you please fill in the following Details?\n"+msg);
			$(obj).removeAttr('style');
		}
		else {
			$('#working').fadeIn('slow',
				function() { 
					$.post($(obj).attr('action')+'?request=true', $(obj).serialize(),
						function(data) { 
							if(data.ok) { 
								$('#working').html('We have received your Enquiry and shall get back to you shortly!');
								$(obj).attr('style', 'opacity:0');
							}
							else { 
								$(obj).removeAttr();
							}
						}, 'json'
					);				
				}
			);
		}	
	}
}
