$(document).ready(function () {  
$(document).pngFix();
var oldone=100;
//$("#main-title-background").fadeTo(0, 0.6);

$("#contact-hint").fadeTo(0,0);
$(".work-example-right-words").each(function(index) {
    $(this).slideUp(0);
});

$('#work-list') 

.cycle({ 
    fx:     'scrollHorz', 
	easing: 'easeInOutCubic',
	slideExpr:'.work-example',
    speed:  1000, 
    timeout: 0, 
	fit:     1, 
	height: 520,
	width: 961,
    pager:  '#work-subnav'
});



$(".work-on").click(function() {

	//$(this).css({'display':'none' });
	
 $(this).slideUp(300);
 //$(this).parent().prev().children().slideUp(400,function() {$(this).next().next().slideDown(400); });
 
 $(this).parent().prev().children().children().fadeTo(400, 0, "easeOutBounce" ,function() {$(this).parent().animate({
  "marginTop": "-480px"
}, 500 ,"easeInBack", function(){$(this).parent().next().next().slideDown(400); });
 });
}


);



$(".work-off").click(function() {

	//$(this).prev().css({'display':'block' });
	$(this).prev().slideDown(300)
 $(this).parent().next().slideUp(400,function(){$(this).prev().prev().children().animate({"marginTop": "0px"}, 500 ,"easeOutBack", function(){$(this).children().fadeTo(400 , 1 , "easeInBounce");})})
}


);


$("a.nav-button").click(function() {
	
	var section = $(this).attr('href')+"-section";
	//var section = "#"+$(this).attr('id').slice(7);
if(section=="#service-section"){
	var offsetnum = 40;
	
}
else{
	var offsetnum = -40;
	
}
	$("a.nav-button:eq("+oldone+")").removeClass("active");
	$(this).addClass( "active" );
	$(window).scrollTo( section, 500, {axis:'y',offset: offsetnum} );
	//window.location.hash = section;
	var index = $("a.nav-button").index(this);
	oldone = index
 
});

$(".to-top").click(function() {
$(window).scrollTo( 0, 500, {axis:'y'} );
});






/*var anchorit = jQuery.url.attr('anchor');
var closeit = null;

if(anchorit!=null){
if(anchorit == "wedding"){
	opendetail(1);
	
}
if(anchorit == "proposal"){
	opendetail(2);
	
}
if(anchorit == "charity"){
	
	opendetail(3);
}
if(anchorit == "corporate"){
	
	opendetail(4);
}
if(anchorit == "marketing"){
	opendetail(5);
	
}
if(anchorit == "entertainment"){
	
	opendetail(5);
}
}*/



function setup_header()
	{
		
		var last_active = 'home';
		var active = '';
		var back_to_top = $('.back_to_top');
		
		
		// scroll amount
		var s = 0;
		
		// section offest - y
		
		var a_y = 0;
		var s_y = 0;
		var t_y = 0;
		var c_y = 0;
		
		
		// set values
		$(window).resize(function(){
			
			a_y = $('#about-section').offset().top;
			s_y = $('#work-section').offset().top;
			t_y = $('#service-section').offset().top;
			c_y = $('#contact-section').offset().top;
		}).trigger('resize');
		
		
		
		$(window).scroll(function(){
		
			s = $(window).scrollTop() + ($(window).height()/4);
			/**/if($(window).scrollTop()+$(window).height()-$('body').height()>=70){
				
				//alert('hello')
				active = "#button-contact";
				
				
				if(active != last_active)
			{
				last_active = active;
				$("#nav").find('.nav-button').removeClass('active');
				$("#nav").find(active).addClass('active');
				
			}
			return false;
			}
			//console.log(s);
			//console.log("t_y: "+ t_y );
		//console.log("s_y: "+ s_y );
			if(s > c_y)
			
			{//console.log(s);
			//console.log("c_y: "+ c_y );
			//console.log($(window).scrollTop()+$(window).height());
			//console.log($('body').height());
				active = "#button-contact";
				
			}
			
			else if (s > t_y)
			
			{
				
				active = "#button-service";
				
			}
			else if (s > s_y)
			{
				active = "#button-work";
				
			}
			else if (s > a_y)
			{
				active = "#button-about";
			
			}
			
			else
			{
				active = "home";
			}
			
			if(active != last_active)
			{
				
				last_active = active;
				$("#nav").find('.nav-button').removeClass('active');
				$("#nav").find(active).addClass('active');
				
				
				
				if(active == "home")
				{
					//back_to_top.stop().animate({'opacity':'0'}, 500, function(){
						//$(this).css({'display':'none'});
					//});
				}
				else
				{
					//back_to_top.stop().css({'display':'block'}).animate({'opacity':'1'}, 500);
				}
			}
			
			
		}).trigger('resize');
		
	}
	
	$('input#fname').focus(function() {
  var fname = $("input#fname").val();
  if(fname =="Name" || fname == "Name is required *"){
	   $("input#fname").removeClass('error');
	  $("input#fname").val("");
	  
  }
});

$('input#email').focus(function() {
  var email = $("input#email").val();
  if(email =="Email Address" || email=="Email is required *"){
	  $("input#email").removeClass('error');
	  $("input#email").val("");
	  
  }
});

$('textarea#comment').focus(function() {
  var comment = $("textarea#comment").val();
  if(comment =="Message"){
	  
	  $("textarea#comment").val("");
	  
  }
});
	
	$(".formbutton").click(function() {
		

	 var fname = $("input#fname").val();
	   if (fname == "" || fname == "Name" ||fname == "Name is required *") {
   $("input#fname").addClass('error');
	  $("input#fname").val("Name is required *");
      //$("input#fname").focus();
      return false;
    }
		
		var email = $("input#email").val();
			 if (email == "" || email =="Email Address" || email=="Email is required *") {
      $("input#email").addClass('error');
	  $("input#email").val("Email is required *");
      //$("input#email").focus();
      return false;
    }
		var comment = $("textarea#comment").val();
		var dataString = 'fname='+ $.trim(fname) + '&email=' + $.trim(email) + '&comment=' + $.trim(comment);
		
	
	$("#contact-hint").fadeTo(200, 1);
	$(".formbutton").attr("disabled", "true"); 	
	$(".formbutton").css("cursor",'default');
	
		$.ajax({
      type: "POST",
      url: "sendmail.php",
      data: dataString,
      success: function() {
		 
		$("#contact-hint").fadeTo(400, 0);
		
	 
	 $("input").not(".formbutton").val("");
	$("input").not(".formbutton").attr("disabled", "disabled"); 	
	 $("textarea#comment").val("Contact Form Submitted! We will be in touch soon.");
	$("textarea#comment") .attr("disabled", "disabled"); 
	 window.setTimeout(function() {
		 
		 $("input#fname").val("Name");
		 $("input#email").val("Email Address");
 $("textarea#comment").val("Message");
$("textarea#comment").removeAttr("disabled")
$("input").not(".formbutton").removeAttr("disabled")	
	$(".formbutton").removeAttr("disabled")	.css("cursor",'pointer');
},4000);
							
	 },
	  
	  error: function(){
	  
		$("#contact-hint").fadeTo(400, 0);
	
		$("input").not(".formbutton").val("");
		$("input").not(".formbutton").attr("disabled", "disabled"); 
	 $("textarea#comment").val("An Error Occur on Our Side! Please send the contact form later.");
		$("textarea#comment") .attr("disabled", "disabled");  
			 window.setTimeout(function() {
  $("input#fname").val("Name");
		 $("input#email").val("Email Address");
 $("textarea#comment").val("Message");
$("textarea#comment").removeAttr("disabled")
$("input").not(".formbutton").removeAttr("disabled")	
	$(".formbutton").removeAttr("disabled")	.css("cursor",'pointer');

},8000);
	
   
																							
	  
	  }
     });
   return false;
	});
	
	

setup_header();

  
  $(window).load(function()
	{
		$(window).trigger('resize');
		
		//setup_team_thumbs();
		
	});
 });  
