// JavaScript Document
$play = true; 

$settings = { 
			thumbs: 2,  
			autoslide: false,  
			asTimer: 5500,  
			typo: false, 
			galBorderWidth: 0, 
			thumbsBorderOpacity: 0,  
			buttonsTextColor: "#707070", 
			buttonsWidth: 40, 
			thumbsActiveBorderOpacity: 0.8, 
			thumbsActiveBorderColor: "aqua", 
			shuffle: false 
		};
var playcounter = 1;
var autoplay; 
function triggerClick(){
	//playcounter = ;
	playcounter = $("div#thumbSlider0 li").index(jQuery("div#thumbSlider0").find("li.active")) + 1;
	if (playcounter>=jQuery("div#thumbSlider0 a").length)
		playcounter=0;
	jQuery("div#thumbSlider0").find("a").eq(playcounter).trigger("click");
	playcounter++;
	}

$(window).bind("load", function() { 

    if ($("div#web-design-works").length > 0)
		{
		$("div#web-design-works").slideViewerPro($settings);
		autoplay = setInterval(triggerClick, 5000);
		// stops or playes slideshow 
		$(".stop, .play").click(function(e){
			e.preventDefault();
			$play = !$play;
			
			if (!$play)
				{
				clearInterval(autoplay);
				
				$(".stop").each(function()
					{
					$(this).addClass("play").removeClass("stop");
					$(this).html('Start slideshow');					
					//$(this).bind("click", function(){$(".play").addClass("stop").removeClass("play");});
					});
				}
			else 
				{
				autoplay = setInterval(triggerClick, 5000);
				$(".play").each(function()
					{
					$(this).addClass("stop").removeClass("play");
					$(this).html('Stop slideshow');
					});				
				}
			});
		}	// if works page
		
	// created mailto links from span with email
	$(".email").each(function(){
		var ats, dots, address, i;
		ats = [' (at) '];
		dots = [' (dot) '];
		address = $(this).html();
		for ( i = 0; i < ats.length; i++ ) {
			address = address.replace(ats[i], '@');
		}
		for ( i = 0; i < dots.length; i++ ) {
			address = address.replace(dots[i], '.');
		}
		$(this).html('&lt;a href="mailto:' + address + '"&gt;' + address + '&lt;/a&gt;');
	});
	
	$("#form-contact").validate({
		rules: {
			fname: "required",
			fsubject: "required",
			femail: {
				required: true,
				email: true
			},
			fmessage: "required",
			agree: "required"
		},
		messages: {
			fname: "My name is Nevena. And yours? ",
			fsubject: "What will this message be about?",
			femail: "Please enter valid email address",			
			fmessage: "Didn't you want to write someting to me? :) "
		}
	});

}); 



