// JavaScript Document
var fixx=false;
jQuery.fn.exists = function(){return jQuery(this).length>0;} 
$.fn.deftext = function(str) {
	$(this).val(str);
	$(this).focus(function () {if ($(this).val()==str) $(this).val("") }); 
	$(this).focusout(function () {if ($.trim($(this).val())=="") $(this).val(str) });
} 
	
$(document).ready(function() {

	if($('#form-contact').length) {
		$('#form-contact').attr('method', 'post');
		$('#form-contact').attr('action', '/mailer.php');
		$('#form-contact input[type=submit]').click(function() {
			var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
			if(reg.test($('#email_address').val())==false) {
				$('#error-mail').html("Please enter a valid e-mail address.");
				$('#error-mail').fadeIn(1000);
			} else {
				$('#error-mail').fadeOut(1000);
				var dataString = 'email_address='+ $('#email_address').val() + '&message=' + $('#message').val();  
				$.ajax({  
					type: "POST",  
					url: "/mailer.php",  
					data: dataString,  
					success: function(data) {  
						$('#form-contact').fadeOut(1000, function() { // Everytime I use .fadeOut() I get Street Spirit stuck in my head
							$('#submit-mail').html('Thank you, your message has been received!');
							$('#submit-mail').fadeIn(1000);
						});
					}
				});
			}
			return false;
		});
	}

	$(".faq-question ~ i").hide();
		$(".faq-question, .about-question").click(function () { 
			$(this).next("i").slideToggle("fast");
		return false;
	});



if ($("#flash").exists()) { $("#flash").flashembed({
src: "flash.swf", 
wmode: 'opaque'
}); }

	
	if ($("#fix-stop").exists()) { 
	 $(window).scroll(function () { 
	     if ($(this).scrollTop() > $("#fix-stop").offset().top-5   )  {
			 if (fixx==false) {$("#menu-sub").addClass("fix"); fixx=true;}
			
			
			// $("#debug").text("dfdf")
			
			 } else if (fixx==true) {$("#menu-sub").removeClass("fix"); fixx=false;}
	    });
	} 	
	
	$("#email_address").deftext("Your Email");
	$("#message").deftext("Your Message");

	$(".tweet").tweet({
	    username: "gapopescu",
	    join_text: "",
	    count: 1,
	    loading_text: "loading tweets..."
	});
		
	if ($("a.demo").exists()) { 		
		$("a.demo").fancybox({
				'transitionIn'	:	'elastic',
				'transitionOut'	:	'elastic',
				'speedIn'		:	600, 
				'speedOut'		:	200, 
				'overlayShow'	:	true,
				'centerOnScroll':   true,
				'overlayOpacity':	0.0,
				'overlayColor'	:	'#374047',
				'width'		: 850,
				'height'		: 531,
				'swf'			: {wmode: 'transparent',
				 				   allowscriptaccess: 'always' ,
  								   allowfullscreen: 'true',
flashvars: 'file=demo.f4v&autostart=true&controlbar=none'
								 }
		});
	}


if($('#quote_ticker').length) {
	get_quotes();
	get_quotes2();
}


});

function get_quotes() {
$.get('/nq/main-renew.php?' + Math.floor(Math.random()*100000), function(data) {
  $('#quote_ticker').html(data);
  
  $('#quote_ticker').css('left', 0);
  $('#quote_ticker').animate({ "left": "-=90em"}, 70000, function(){
		get_quotes() ;
  }); // Animate
  
});
}

function get_quotes2() {
	$.get('/nq/main.php?' + Math.floor(Math.random()*100000), function(data) {
	  $('#quote_ticker2').html(data);
		
		setTimeout(' get_quotes2(); ', 1000) ;
	});
}



