var siteurl = 'http://www.graphxevolution.com/';
var contactform;

function loadfancybox() {
	$('a[rel=fancybox]').fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200,
		'titlePosition'	:	'inside'
  	});
}

function getcontactform() {
}

$(document).ready(function() {
	
	loadfancybox();
	$.jGrowl.defaults.position = 'top-left';
	
	$.ajax({
			type : "GET",
			url : siteurl+'includes/contactform.php',
			dataType : "html",
			success: function(data) {
				contactform = data;	

			},
			error : function() {
				contactform = "Sorry, The requested property could not be found.";
			},
			async: false
	});
	
	$(function(){
        $('#questions').tabSlideOut({
            tabHandle: '.tab',
            tabLocation: 'left',
            speed: 300,
            action: 'click',
            topPos: '115px',
            leftPos: '20px',
            fixedPosition: true
        });
    });
	
	$('.contact a').qtip({
		style: { 
			width: 600,
			padding: 10,
			//background: '#ffffff',
			color: '#444444',
			textAlign: 'left',
			border: {
				width: 3,
				radius: 3,
				color: '#a7aaac'
			},
			tip: 'rightTop',
			title: {
				//'background': '#ebebeb',
				'background': '#fff',
				'font-size': '1.4em',
				'line-height': '1.3em'
			},
			classes: {
					active: 'contact_tip'
			}
		},
		name: 'light', // Inherit the rest of the attributes from the preset dark style
		show: {
			effect: {
				length: 'fast'
			},
			when: {
				event: 'click'
			}
		},
		content: {
		   text: contactform,
		   title: {
			  text: '',
			  //button: '<img src="https://fedorahosted.org/echo-icon-theme/export/f3da1be0d69c2e53acb18cc81d15ba6002b7413c/base/256x256/actions/dialog-close.png" width="30" style=" position:absolute; top:-7px; left:-20px;" />'
			  button: '<img src="'+siteurl+'images/dialog-close.png" width="30" style=" position:absolute; top:-5px; left:-25px;" />'
		   }
		},
		hide:false,
		position: {
			corner: {
				target: 'leftBottom',
				tooltip: 'rightTop'
			},
			adjust: {
				x: 20,
				y: -20
			}
		},
		api: {
			onShow: function() {
					var i = 0;
					$('.qtip-wrapper #frmContact input#return').remove();
					$('.qtip-wrapper #frmContact').submit(function() {
							if(i==0) {
							$(this).ajaxSubmit({
								resetForm: true,
								dataType: 'json',
								beforeSubmit: function() {
										 return $('.qtip-wrapper #frmContact').validate({
												rules: {
													name:"required",
													email: {
														required: true,
														email: true
													},
													url: {
														url: true
													}
												},
												messages: {
													name: "Don't be shy..",
													email: {
														required: "How are we supposed to contact you without this?",
														email: "That's not an email address!"
													},
													url: "Please provide a valid url."
												}
											}).form();
									 },
								success: function(data) {
										if(data.sent) {
											$('.contact a').qtip("hide");
											$.jGrowl("Someone will be contacting you shortly.",
													 {
														 header: 'Thank You!'
													 });
					
										}
										i++;
									}					   
								}); 
							}
							return false; 
						});
			},
			beforeShow: function() {
				// Fade in the modal "blanket" using the defined show speed
				$('#qtip-blanket').fadeIn(this.options.show.effect.length);
			 },
			 beforeHide: function() {
				// Fade out the modal "blanket" using the defined hide speed
				$('#qtip-blanket').fadeOut(this.options.hide.effect.length);
			 }
		}				
	}).click(function(e) {
			e.preventDefault();
	});
	
	$('<div id="qtip-blanket">')
      .css({
         position: 'absolute',
         top: $(document).scrollTop(), // Use document scrollTop so it's on-screen even if the window is scrolled
         left: 0,
         height: $(document).height(), // Span the full document height...
         width: '100%', // ...and full width

         opacity: 0.7, // Make it slightly transparent
         backgroundColor: 'black',
         zIndex: 5000  // Make sure the zIndex is below 6000 to keep it below tooltips!
      })
      .appendTo(document.body) // Append to the document body
      .hide(); // Hide it initially
	
	$('#frmQuestion').submit(function() {
		$(this).ajaxSubmit({
			resetForm: true,
			dataType: 'json',
			beforeSubmit: function() {
					 return $('#frmQuestion').validate({
							rules: {
								question:"required",
								email: {
									required: true,
									email: true
								},
								human: {
									required: true,
									equalTo: "#hcheck"
								}
							},
							messages: {
								question: "Um, you forgot something..",
								email: {
									required: "How are we supposed to answer you without this?",
									email: "That's not an email address!"
								},
								human: {
									required: "We need to make sure you're human and not a spammer.",
									equalTo: "Hmm, you sure about that?"
								}
							}
						}).form();
				 },
			success: function(data) {
					if(data.sent) {
						obj = $('#questions');
						containerWidth = parseInt(obj.outerWidth(), 10) + 'px';
						obj.animate({left: '-' + containerWidth}, 300).removeClass('open');
						$.jGrowl("Someone will be answering your question shortly.",
								 {
									 header: 'Thank You!'
								 });

					}
				}					   
			}); 
		return false; 
    }); 
});
