// JavaScript Document
jQuery(document).ready(function()
{

//----------
// main slideshow settings
//----------

jQuery('#slider').cycle({
		fx: 'scrollHorz',        
		speed:  'slow',
		easing: 'easeOutExpo',
        timeout: 6000,
		cleartypeNoBg: true,
		cleartype:  1,
		pause: 1,
		pager:'#sl_controls', 	
		pagerAnchorBuilder: function(idx, slide) { return '<li><a href="#"></a></li>'; }
});

//----------
// screenshots settings
//----------

jQuery ('#screenshot').cycle({
		fx: 'scrollHorz',        
		speed:  'slow',
		easing: 'easeOutExpo',
		prev:   '#prev_slide', 
    	next:   '#next_slide',
        timeout: 0,
		cleartypeNoBg: true,
		cleartype:  1,
		pause: 1
});

//----------
// testimonials settings
//----------

jQuery ('#testimonials').cycle({
		fx: 'scrollHorz',        
		speed:  'slow',
		easing: 'easeOutExpo',
        timeout: 6000,
		cleartypeNoBg: true,
		cleartype:  1,
		pause: 1
});


kostadino_form();
kostadino_animation();
kostadino_lightbox();

});

///////////////////////////////////////////////////////////////////////////////////// 


//----------
// form / label fade out / newsletter validation
//----------
function kostadino_form(){
	
	//----------
	// label animation 
	//----------
	
	$(function(){ $("label").inFieldLabels(); }); 
	
	
}


//----------
// animation
//----------
function kostadino_animation(){	
	
	
	//----------
	// video animation and controls
	//----------
	
	$("#video").click(function() {
		$("#video").animate({opacity: "hide", right: "-40px"}, "fast");
		$("#screens").animate({opacity: "show", right: "0px"}, "slow");
		$("#vertical_placeholder").slideUp("slow","easeOutExpo");
		$("#sl_controls").animate({opacity: "hide"}, "fast");
	});
	
	$("#screens").click(function() {
		$("#video").animate({opacity: "show", right: "0px"}, "slow");
		$("#screens").animate({opacity: "hide", right: "-40px"}, "fast");
		$("#vertical_placeholder").slideDown("slow","easeOutExpo");
		$("#sl_controls").delay(1000).animate({opacity: "show"}, "slow");		
	});
	
	$("#vertical_controls").toggle(function() {
		$('#slider').cycle('pause', true);
        }, function() {
        $('#slider').cycle('resume'); 
    }); 
	
}


//----------
// fancybox lightbox
//----------
function kostadino_lightbox(){
	
	$("a[rel=fancyzoom]").fancybox();
	
	$("a[rel=fancyzoom_group]").fancybox();
	
	//----------
	// fancybox vimeo 
	//----------
	$("a[rel=fancyvimeo]").click(function() {
		$.fancybox({
				'padding'		: 0,
				'autoScale'		: false,
				'title'			: this.title,			
				'href'			: this.href.replace(new RegExp("[0-9]", "i"), 'moogaloop.swf?clip_id=1'),
				'type'			: 'swf',
				'swf'			: {'wmode':'transparent','allowfullscreen':'true'}
		});

	return false;
	});	
	
	//----------
	// fancybox youtube 
	//----------
	$("a[rel=fancytube]").click(function() {
		$.fancybox({
				'padding'             : 0,
				'autoScale'   : false,
				'transitionIn'        : 'none',
				'transitionOut'       : 'none',
				'title'               : this.title,
				'width'               : 680,
				'height'              : 495,
				'href'                : this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
				'type'                : 'swf',    // <--add a comma here
				'swf'                 : {'allowfullscreen':'true', 'wmode':'opaque'} // <-- flashvars here
		}); 

	return false;
	});	
	
}

//----------
// contact
//----------

/* holder for form variables */
var stringVars='';

/* Function to clear form */
function clearForm()
{
	for(i=0; i< document.contact.elements.length; i++)
	{
		if(document.contact.elements[i].type.search(/text/) != -1)
		{
			document.contact.elements[i].value='';
		}
	}
}

/* Function to submit form */
function submitForm()
{
	if(document.getElementById('form_error').style.display == 'none')
	{
		document.getElementById('form_error').style.display='inline';
	}
	
	document.getElementById('error_msg').innerHTML = '<img src="img/loading.gif">';
	
	for(i=0; i< document.contact.elements.length; i++)
	{
		switch(document.contact.elements[i].type)
		{
			case 'text':
			case 'textarea':
			case 'radio':
			case 'select-one':
			stringVars += escape(document.contact.elements[i].name)+'='+escape(document.contact.elements[i].value)+'&';
			break;		
			case 'checkbox':
			if (document.contact.elements[i].checked){
				temp = document.contact.elements[i].name;
				temp = temp.replace(/\[]/,'');
				stringVars += escape(temp)+'='+escape(document.contact.elements[i].value)+'&';	
			}
		}
	}
	doCall();
}
function doCall()
{
	http.open("GET", 'contact.php?' + stringVars, true);
	http.onreadystatechange = handleHttpResponse;
	http.send(null);
}

function handleHttpResponse()
{
	if (http.readyState == 4)
	{
		var response = http.responseText;				
		document.getElementById('error_msg').innerHTML = response;
		
		if(response.search(/<!---->/) != -1){
			clearForm();
		}
	}
}

function getHTTPObject()
{ 
	var xmlhttp;
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			xmlhttp = false;
		}
	}
	return xmlhttp;
}
var http = getHTTPObject(); 

