$(document).ready(function(){
	$("#tadd").click(function(){Home.testForm();});
	
	$.get('ajax.php?action=topdogs',
		function(d){
			$('#popdogs').removeClass('top-loader');
			$('#popdogs').html(d);
		}
	,'html');
	$.get('ajax.php?action=topcats',
		function(d){
			$('#popcats').removeClass('top-loader');
			$('#popcats').html(d);
		}
	,'html');
	$.get('ajax.php?action=testimonial&site=aaa',
		function(d){
			$('#testimonials').removeClass('test-loader');
			$('#testimonials').html(d);
		},
		'html');
	$.getScript('http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js',
		function(){
			var flashvars = false;
			var params = {
			  menu: "false",
			  wmode: "transparent",
			  flashvars: "site=http://www.aaapets.com/&bordercolor=856306&txtcolor=BF6000"
			};
			var attributes = {
			  id: "pet_gallery",
			  name: "pet_gallery"
			};
			swfobject.embedSWF("http://www.aaapets.com/slideshow.swf", "petgallery", "150", "175", "9.0.0","images/expressInstall.swf", flashvars, params, attributes);
		});
		
		$.getScript('http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js',
			function(){
				var flashvars=false;
				var params = {
					wmode:"transparent",
					menu:"false",
					flashvars:"site=http://www.aaapets.com/&bordercolor=856306&txtcolor=BF6000"
				};
				
				var attributes = {
					id:"web_gallery",
					name:"web_gallery"
				};
				swfobject.embedSWF("http://www.aaapets.com/web_slideshow.swf","webgall","150","115","9.0.0","expressInstall.swf",flashvars,params,attributes);
				
			});
});

var Home = {
	goto:function(_url, _target) {
		window.open(_url, _target);
	},
	maxchars:function(){
		$('#comment').maxchars({
			'status': true,
			'maxCharacters': 1000,
			'statusText': "character left",
		});	
	},
	testForm:function(){
		$("head").append("<link >");
			css = $("head").children(":last");
			css.attr({
				rel:  "stylesheet",
				type: "text/css",
				href: "css/forms.css"
			});
		$.get('ajax.php?action=testimonialtpl',
			function(d){
				$("#testbox").html(d).show();
				$("#testbox").modal({
					opacity: 50,
					position: [100,0],
					containerCss :{
						height: 375,
						width: 400
					},
					onOpen: function (dialog) {
						dialog.overlay.fadeIn('slow', function () {
							dialog.container.fadeIn('slow', function () {
								dialog.data.fadeIn('slow', function () {
									$.getScript('js/jquery.maxchars.js',
										function(){
										Home.maxchars();
										$.getScript('js/jquery.validate.js',
											function(){
												$("#form-testimonial").validate({
													submitHandler:function(form){
														var values = $('#form-testimonial').serialize();
														Timer.resetTimeout();
														Timer.initTimeout();
														$('#theform').hide();
														$("#simplemodal-container").animate({height:60},
															function(){
																$('#loader').show();
																$.get('ajax.php?'+values,
																	function(d){
																		$("#loader").hide();
																		$("#simplemodal-container").animate({height:100},
																			function(){
																				$("#theform").html(d).show();
																				setTimeout("window.location.reload()",5000);
																			});
																	});
															});
													},
													rules: {
														name: {
															required: true,
															minlength: 3
														},
														title: {
															required: true,
															minlength: 3
														},
														comment: {
															required: true
														}
													}
												});
											});
										});
									});
							});
						});
					},
					onClose: function (dialog) {
						dialog.data.fadeOut('slow', function () {
							dialog.container.fadeOut('slow', function () {
								dialog.overlay.fadeOut('slow', function () {
									$.modal.close();
									$("#testbox").html('').hide();
								});
							});
						});
					}
				});
		});
	}
}
