﻿$(function () {
	window.remoteURL = '/php/index.php';
	jQuery('.error').hide();

    $('#slide').cycle({
        timeout: 8000,  // milliseconds between slide transitions (0 to disable auto advance)
        fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...            
        pause: 0,   // true to enable "pause on hover"
        pauseOnPagerHover: 0, // true to pause when hovering over pager link
        next: '.next',  // selector for element to use as click trigger for next slide 
        prev: '.prev',  // selector for element to use as click trigger for previous slide 
        cleartypeNoBg: true // set to true to disable extra cleartype fixing (leave false to force background color setting on slides) 
    });

    $('.cycle-box').cycle({
        timeout: 8000,  // milliseconds between slide transitions (0 to disable auto advance)
        fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...            
        pause: 0,   // true to enable "pause on hover"
        pauseOnPagerHover: 0, // true to pause when hovering over pager link
        cleartypeNoBg: true // set to true to disable extra cleartype fixing (leave false to force background color setting on slides) 
    });

	$('.fancybox').fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	600, 
		'overlayShow'	:	false,
		'cyclic': true
	});

    $(".pf-type1 a[rel^='prettyPhoto']").prettyPhoto({ theme: 'dark_rounded' });
	initSearch();
});

function checkContactForm() {
	fStatus = true;
	var name = jQuery("input#name").val();
	if (name == "") {
		jQuery("span#name_error").show();
		jQuery("input#name").focus();
		fStatus = false;
	}
	var email = jQuery("input#email").val();
	if (email == "") {
		jQuery("span#email_error").show();
		jQuery("input#email").focus();
		fStatus = false;
	}
	
	var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
	if(!emailReg.test(email)) {
		jQuery("span#email_error2").show();
		jQuery("input#email").focus();
		fStatus = false;
	}
	
	var msg = jQuery("textarea#msg").val();
	if (msg == "") {
		jQuery("span#msg_error").show();
		jQuery("textarea#msg").focus();
		fStatus = false;
	}

	return fStatus;
}
function submitContactForm() {
	if (checkContactForm()) {
		fArray = $('#contactForm').serializeArray();
		$.post(window.remoteURL, fArray, function(data) {
			$('#contact_form').fadeOut(300, function() {
				$('#contact_form').html(data);
				$('#contact_form').fadeIn(300);
			});
		});
	}
}

function initSearch() {
	$.ajax({
		url: '/files/xml/search.xml',
		dataType: "xml",
		success: function(xmlResponse) {
			var data = $("item", xmlResponse).map(function() {
				return {
					type: $("type", this).text(),
					id: $("id", this).text(),
					value: $("name", this).text(),
					body: $("body", this).text(),
					url: $("url", this).text()
				};
			}).get();

			$("#searchbox").autocomplete({
				source: data,
				minLength: 1,
				select: function(event, ui) {
					location.href = ui.item.url;
				}
			});
		}
	});
}

function openBlogPost(fID) {
	fancyboxLoader('Loading Post...', function() {
		$.post('/php/index.php?pid=30&spid=view&linkid='+fID, {}, function(data) {
			fancyboxDisplay(data);
		})
	})
}
