$(document).ready(function() {

	// Clear default values
	$('input[type="text"], textarea').focus(function(){ if( this.value == this.defaultValue ) { this.value = ""; }}).blur(function() { if( !this.value.length ) { this.value = this.defaultValue; } });
	
	$(".popup, a[rel^='prettyPhoto']").prettyPhoto({show_title: false, overlay_gallery: false});
	$('.jqtransform').jqTransform();

	// Dropdown menu
	$('.hasSub').hover( 
		function() { $(this).children('ul').fadeIn(100); }, 
		function() { $(this).children('ul').fadeOut(100); } 
	);
	
	// Subscribe
	$('#sForm').submit(function() {
		var email = $('#sEmail').val();
		$.ajax({
			type: "POST",
			async: false,
			url: "/ajaxs/subscribe/"+email,
			success: function(data){
				alert(data.msg);
				if (data.sent == '1') $('#sEmail').val('el.pašto@adresas.lt');
			}
		});			
		return false;;
	});	
	
	// Query
	$('#qForm').submit(function() {
		var dataString = $(this).serialize();
		$.ajax({
			type: "POST",
			async: false,
			url: "/ajaxs/query/",
			data: dataString,
			success: function(data){
				alert(data.msg);
				if (data.status == 1)
					$('#qForm').clearForm();
			}
		});			
		return false;;
	});	
	
});

$(function() {
    $('#banner-inner').cycle({
        fx: 'fade',
        speed: 1000,
        pause: true,
        timeout: 5000,
        pager: '#nav',
        next: '.next',
        activePagerClass: 'active',
        pagerAnchorBuilder: function(idx, slide) { return '#nav li:eq(' + (idx) + ') a'; }
    });
});

// Clear Form
$.fn.clearForm = function() {
	return this.each(function() {
		var type = this.type, tag = this.tagName.toLowerCase();
		if (tag == 'form')
			return $(':input', this).clearForm();
		if (type == 'text' || type == 'password' || tag == 'textarea')
			this.value = '';
		else if (type == 'checkbox' || type == 'radio')
			this.checked = false;
		else if (tag == 'select')
			this.selectedIndex = 0;
	});
};
