﻿// JavaScript Setup

// jQuery Init
jQuery.noConflict();
jQuery(function($) { 
	
	
	
	
	// Back to top section links for non-IE browsers
	if ( ! $.browser.msie ) {
		$('.section').children('h3').append("<a href='#virsus' class='scrollTop hidden' title=''></a>");
		$(".section").hover(
			function(){
				$(this).find(".scrollTop").css('display', 'block');
			},
			function(){
				$(this).find(".scrollTop").css('display', 'none');
			}
		);
	}
	
	
	// Panel Toggle in Header
	$("#panel_toggle").click(function(){
	  $("#panel").slideToggle(300, function(){ $("#panel_toggle").toggleClass("panel_active"); });	  
	});
		
	
	
	// *****************************	
	// Start - jQuery Fancybox setup


		// How tos at http://fancybox.net/
		$('a[href$="jpg"], a[href$="jpeg"], a[href$="png"], a[href$="gif"]').fancybox();
		
		// Fancybox - Youtube
		// <a class="youtube" title="The Social Network" href="http://www.youtube.com/watch?v=lB95KLmpLR4">Try now</a>
		
		
			$(".tip4").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',
			'swf'			: {
			   	 'wmode'		: 'transparent',
				'allowfullscreen'	: 'true'
			}
		});

	return false;
});
		
		
		
		$(document).ready(function() {$("#testas").click(function() {$.fancybox({'padding': 0,'autoScale': false,'hideOnOverlayClick': false,'transitionIn': 'none','transitionOut': 'none','title': this.title,'width': 640,'height': 360,'href': this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),'type': 'swf','swf': {'wmode': 'opaque','allowfullscreen': 'true'}});return false;});});
		


		
	// End - Query Fancybox setup
	// *****************************	
	
	
	
	
	// Clear form field on click
	$("form.standard .textbox,form.standard .textarea").focus(function() {
		if( this.value == this.defaultValue ) {
			this.value = "";
		}
	}).blur(function() {
		if( !this.value.length ) {
			this.value = this.defaultValue;
		}
	});
	
	
	
	
	
	
	
	
	
	// Used to scroll to a specific position.
	// Edit the variables below to adjust speed and positioning
	var scrollDuration = 500; // 1000 = 1 second
	var scrollGap = 0; // in Pixels, the gap left above the scroll to point
	$('a[href*=#virsus]').click(function() 
	{
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) 
		{
			var $target = $(this.hash);
			$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
			if ($target.length) 
			{
				var targetOffset = $target.offset().top - scrollGap;
				$('html,body').animate
					(
					{scrollTop: targetOffset}, 
					scrollDuration
					);
				return false;
			}
		}
	});

	
	
		
	// Softbutton = soft fade on hover, used for social media icons
	$(".softbutton").stop().fadeTo("fast", 0.4);
	$(".softbutton").hover(
		function(){
			$(this).stop().fadeTo("fast", 1);
		},
		function(){
			$(this).stop().fadeTo("fast", 0.4);
		}
	);
	
	
	// Toggle Content!
	$(".hidden").hide();
	$("a.toggle").click(function(event){
		if( $(this).text() == 'Daugiau' ) {
			$(this).text("");
		}else{
			$(this).text("");
		}
		if( $(this).text() == 'More' ) {
			$(this).text("");
		}else{
			$(this).text("");
		}
		if( $(this).text() == 'Больше' ) {
			$(this).text("");
		}else{
			$(this).text("");
		}
		$(this).parents(".toggle-container").find(".hidden").slideToggle("normal");
		return false;
	});


	
	
	
	// contact form
	// Stop form from traditionally submitting if JavaScript is enabled
	$("#contact_form form").attr("action","");
	
	$("#siusti").click(function() {
		var vardas = $("#vardas").val();
		var pastas = $("#pastas").val();
		var tel = $("#tel").val();
		var zinute = $("#zinute").val();		
		var hasError = false;
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		
		if(vardas == '' || vardas == 'Vardas') {
			$("#error-name").fadeIn();
			hasError = true;
		}else{
			$("#error-name").fadeOut();
		}
		
		if(pastas == '' || pastas == 'El. Paštas') {
			$("#error-email").fadeIn();
			hasError = true;
		}else if(!emailReg.test(pastas)) {
			$("#error-email").fadeIn();
			hasError = true;
		}else{
			$("#error-email").fadeOut();
		}
		
		if(zinute == '' || zinute == 'Žinutė') {
			$("#error-message").fadeIn();
			hasError = true;
		}else{
			$("#error-message").fadeOut();
		}
		
		if(tel == '' || tel == 'Tel.') {
			tel = "Telefono numeris nenurodytas";
		}
			
		if(hasError == true)
		{
			return false;
		}
				
		var formData = 'vardas=' + vardas + '&tel='+ tel + '&pastas=' + pastas + '&zinute=' + zinute;
		var successPlaceholder = "<div id='message'></div>";
		var successHTML = "<h4>Ačiū!</h4><p>Atsakymą gausite netrukus.</p>";
		
		$.ajax({
			type: "POST",
			url: "siusti.php",
			data: formData,
			success: function() {
				$('#contact_form').html(successPlaceholder);
				$('#message').html(successHTML);
			}
		}); // end ajax post
		return false;
	});
	// end contact form
	
	
});
