var issc=true;

jQuery.fn.exists = function(){return jQuery(this).length>0;} 
$.fn.deftext = function() {
	var str=$(this).val();
	$(this).val(str);
	$(this).focus(function () {if ($(this).val()==str) $(this).val("") }); 
	$(this).focusout(function () {if ($.trim($(this).val())=="") $(this).val(str) });
} 

function slideSwitch(who) {
    var $active = $(who+' DIV.active');
    if ( $active.length == 0 ) $active = $(who+' DIV:last');
    var $next =  $active.next().length ? $active.next()
        : $(who+' DIV:first');

    // uncomment below to pull the divs randomly
     var $sibs  = $active.siblings();
     var rndNum = Math.floor(Math.random() * $sibs.length );
     var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}



$(document).ready(function() {

//Secret
	$("#secret-list").easydrag();
 
	// set a function to be called on a drop event
	$("#secret-list").ondrop(function(e, element)
	{ 							
	$("#secret-list").animate({left: "774px",top: "91px"}, 1000 );				 	 
	});


//TOP MENU
var topmenuh=-($("#topmenu").height());
$("#topmenu").css("top",topmenuh+"px");

$("#topmenu").hover(
      function () {
        $(this).stop().animate({top: "0px","opacity": 1}, 300 );	
      }, 
      function () {
        $(this).stop().animate({top: topmenuh+"px"}, 300 );
		issc=true;
      }
    );
$("#topmenu li.hasSubmenu").hover(
      function () {
        $(this).find("ul").show();	
      }, 
      function () {
        $(this).find("ul").hide();
      }
    );
$(window).scroll(function () { 
if (issc) {$("#topmenu").stop().animate({"opacity": 0.8,top: topmenuh+"px"}); issc=false;}
if ($(this).scrollTop()<=0) {$("#topmenu").stop().animate({"opacity": 1}, 300); issc=true;}	
	});	
	
//end TOP MENU

//Index portfolio

if ($("#portfolio-box").size != 0) {
 setInterval( "slideSwitch('#porfolio-box')", 3000 );	
}


//contact us
	$("#inp-name").deftext();
	$("#inp-mail").deftext();
	$("#text-message").deftext();
	$("#special-interests").deftext();
	$("#resume-portfolio").deftext();
	$("#why-me").deftext();
	$("#summ-name").deftext();
	$("#summ-email").deftext();
	$("#summ-phone").deftext();
	
//STAAAAAAAARRRRRRRRRRRRRTTTTTTTTTTTTTTTT	
	$("#contact-submit").click(function(){
			var error="";
		$("#status-mail").hide();
			
			if($("#inp-name").val()=="Your Name") {
				error="Please enter your name. <br />";
			}
			
			if($("#inp-mail").val()=="Your Email or Phone") {
				error+="Please enter email or phone. <br />";
			}
			
			if (($("#text-message").val()=="Your Message"))
			{error+="Please enter your message. <br />";}
			
				if (error != "") {
				$('#status-mail').html(error);
				$('#status-mail').fadeIn(600);
				}
				else {
			$('#status-mail').hide();
			$("#loading-icon").show();		
			
			var dataString = 
			'name='+		  $("#inp-name").val()+
			'&email='+ 	  $("#inp-mail").val() + 
			'&message=' + $("#text-message").val();  
			
				$.ajax({  
					type: "POST",  
					url: "../mailer.php",  
					data: dataString,  
					cache:false,
					error: function(data) {alert("Try again later");},
					success: function(data) { 
					$("#loading-icon").hide();
					$("#contact-form").fadeOut(300, function () {
					$("#after-submit").fadeIn(300).delay(2000).fadeOut(300,  
			function () {$("#contact-form").fadeIn(300)});}); 
													
					}
				});

					}
		return false;
		});
		
		
		
$("#summary-submit").click(function(){
				var error="";
				var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
			$("#status-mail").hide().removeClass("ok-msg");
			if($("#summ-name").val()=="Name") {
				error="Please enter your name. <br />";
			}
			
			if(reg.test($("#summ-email").val())==false) {
				error+="Please enter a valid email. <br />";
			}
			
			if ($("#summ-phone").val()=="Phone")
			{error+="Please enter your phone. <br />";}
			
			if ($("#special-interests").val()=="Special interests")
			{error+="Please enter special interests. <br />";}
			
			if ($("#resume-portfolio").val()=="Paste your resume / cover letter / portfolio here")
			{error+="Please paste your resume / cover letter / portfolio here. <br />";}
			
			if ($("#why-me").val()=="Why me?")
			{error+="Please enter Why me?";}
			
				if (error != "") {
				$('#status-mail').html(error);
				$('#status-mail').fadeIn(600);
				}
				else {
			$('#status-mail').hide();
			$("#loading-icon").show();		
			var dataString = 
			'vacancy='+	  $("#vacavcy").val()+
			'&name='+	  $("#summ-name").val()+
			'&mail='+ 	  $("#summ-email").val() + 
			'&phone=' +   $("#summ-phone").val()+
			'&country=' + $("#summ-country").val()+
			'&special-interests=' + $("#special-interests").val()+
			'&resume-portfolio=' + $("#resume-portfolio").val()+ 
			'&why-me=' +  $("#why-me").val(); 
			
				$.ajax({  
					type: "POST",  
					url: "mailer_summ.php",  
					data: dataString,  
					cache:false,
					error: function(data) {alert("Try again later");},
					success: function(data) { 
					$("#loading-icon").hide();
					$("#status-mail").addClass("ok-msg");
					$('#status-mail').html("Your message was sent.");
					$('#status-mail').fadeIn(600);
													
					}
				});
			

					}
	return false;
		});



//PORTFOLIO
$(".portfolio-box-image").toggle(
      function () { 
	    
        $(this).stop().animate({height: "548px"}, 300
		//,function (){$(this).offsetParent().find(".portfolio-comment").fadeIn()}
		);
      }, 
      function () {
		 // $(this).offsetParent().find(".portfolio-comment").hide();
		  
         $(this).stop().animate({height: "220px"}, 300 );
      }
    );

// portf filter
$("#portfolio-filter li a").click( function () {
	
	$("#portfolio-filter li a").removeClass("active");
	$(this).addClass("active");
	 var title = $(this).attr("id");
	 if (title=="all-f") {$(".portfolio-box").show(500);} else
	 if (title=="webdesign-f") {
		 $(".identity-f").hide(500);
		 $(".webdesign-f").show(500);
		 } else
	if (title=="identity-f") {
		 $(".identity-f").show(500);
		 $(".webdesign-f").hide(500);
		 } 
	return false;
	});
	
//OUR STAFF
$(".member-photo").css({opacity: 0.8});
$(".member-photo").hover(
      function () { 
        $(this).stop().animate({opacity: 1}, 300 );	
      }, 
      function () {
        $(this).stop().animate({opacity: 0.8}, 300 );
      }
    );

	
//JOB
$("#details-codeigniter-link").click(
	
      function () {
		  $("#details-codeigniter").toggle(); return false;});
		  
$("#details-writer-link").click(
	
      function () {
		  $("#details-writer").toggle(); return false;});		  	
		  
		  
//SECRET
$("#sknopka").hover(
		function() { $(this).removeClass().addClass("coll")
					 $("#scvetok").removeClass().addClass("cofl")},
        function() {$(this).removeClass().addClass("cola")
					$("#scvetok").removeClass().addClass("cofa")}
		);


$("#sleft, #sright, #listing li").css("opacity",0.5);
$("#sleft, #sright, #listing li").hover(
		function() { $(this).css("opacity",1);},
        function() {if ( $(this).hasClass("active") ) {$(this).css("opacity",1);} else $(this).css("opacity",0.5);     });

var kolvo=9;
var screennow=1;
var x=(screennow-1)*700;
function testpm() {
	if (screennow<=1) {$("#sleft").hide(); screennow=1} else $("#sleft").show()
	if (screennow>=kolvo) {$("#sright").hide(); screennow=kolvo} else $("#sright").show()
	$("#listing li").css("opacity",0.5).removeClass();
	$("#listing li:eq("+(screennow-1)+")").css("opacity",1).addClass("active");;						 

}
testpm();
$("#sleft").click(function () {						
 screennow--;
 testpm();
 x+=700;

  $("#scrooo").stop().animate({
      left: x
    }, 1000, "easeOutElastic");

 
});		

$("#sright, #rightt").click(function () {						
screennow++;
testpm();
x-=700;

  $("#scrooo").stop().animate({
      left: x
    }, 1000, "easeOutElastic");
 });	

$("#listing li").click(function () { 
		$("#listing li").css("opacity",0.5).removeClass();						 
		$(this).css("opacity",1);
		$(this).addClass("active");
		screennow=$("ul#listing li").index(this)+1;
		testpm();
 		x=-(screennow-1)*700;
		$("#scrooo").stop().animate({
      left: x
    }, 1000, "easeOutElastic");
		

								 });
		  
  });

