$(document).ready(function() {
	
	$('.segmentInfo').css("display", "block");
	
	$('nav ul li').last().css('margin','0');
	
	revealer();


$('[placeholder]').focus(function() {
  var input = $(this);
  if (input.val() == input.attr('placeholder')) {
    if (this.originalType) {
      this.type = this.originalType;
      delete this.originalType;
    }
    input.val('');
    input.removeClass('placeholder');
  }
}).blur(function() {
  var input = $(this);
  if (input.val() == '') {
    if (this.type == 'password') {
      this.originalType = this.type;
      this.type = 'text';
    }
    input.addClass('placeholder');
    input.val(input.attr('placeholder'));
  }
}).blur();

// icon rollovers
	$('#sidebar h2, #sidebar h3').find('a').hoverIntent(function () {
        $(this).find('span').animate({
            'top': '-48px'
        }, 200);
    }, function () {
        $(this).find('span').animate({
            'top': '0'
        }, 200, function () {
            $(this).find('span').css('top', 0);
        });
    });
	
	$('.facebook-icon, .share-icon').find('a').hoverIntent(function () {
        $(this).animate({
            'top': '-48px'
        }, 200);
    }, function () {
        $(this).animate({
            'top': '0'
        }, 200, function () {
            $(this).css('top', 0);
        });
    });

// back to top
	$("#back-top").hide();
	
	$(function () {
		$(window).scroll(function () {
			if ($(this).scrollTop() > 100) {
				$('#back-top').fadeIn();
			} else {
				$('#back-top').fadeOut();
			}
		});

		$('#back-top a').click(function () {
			$('body,html').animate({
				scrollTop: 0
			}, 300);
			return false;
		});
	});

// reveal overlay
function revealer(){	
	$('.reveal').fadeTo(250, 0);
	
	$('.reveal').hover(function(){
		$(this).stop(true, true).fadeTo(250, 1.0);
	},function(){
		$(this).stop(true, true).fadeTo(250, 0);
	});
	
// reveal projects
	$('.reveal2').fadeTo(250, 0);
	
	$('.reveal2').hover(function(){
		$(this).stop(true, true).fadeTo(250, 1.0);
	},function(){
		$(this).stop(true, true).fadeTo(250, 0);
	});
}
	
// filter box
	$('.filters li a').click(function(){
		if ($(this).hasClass('selected')){
			$(this).removeClass('selected');
		}
		else{
			$(this).addClass('selected');
		}
	});
        
        $('form#mainForm').bind('submit', function(e){
        e.preventDefault();
        checkForm();
    });
    
    $('input#hostName').focus();


	
	function lastAddedLiveFunc() 
	{ 
                var firstid = $(".wrdLatest:last").attr("id");
		$.post("/scripts/getPortfolios.scr.php?action=getLastPosts&lastPostID="+$(".wrdLatest:last").attr("id"),

		function(data){
                    
			if (data != "") {
			$(".wrdLatest:last").after(data);
                        
				$('#start'+firstid+' img').each(function(i) {
					$(this).delay(i*200).css('opacity',0).animate({opacity:1}, 1000);
				});
				
				revealer();
			}
		});

	};  
	
	$(window).scroll(function(){
            
               //var docHeight = $(document).height()-271;
               var docHeight = $(document).height();
               var windowHeight = $(window).height();
               var pageHeight = (docHeight - windowHeight);
               //var scrollTop = $(window).scrollTop()-54;
               var scrollTop = $(window).scrollTop();

                if  (scrollTop == pageHeight){
		   lastAddedLiveFunc();
		}

                //$(".wrdLatest:last").after(lastAddedLiveFunc());
                
	}); 
	

//end jQuery
});


//Home slide up-down
	var sliderHeight = "120px";

	$(document).ready(function(){
		$('.slider').each(function () {
					var current = $(this);
					current.attr("box_h", current.height());
				}
		 );
		
		$(".slider").css("height", sliderHeight);
		
		$(".slider_menu").html('<a href="#">Read More</a>');
		$(".slider_menu a").click(function() { 
		openSlider()
		return false;
		 })
	});

	function openSlider()
	{
		var open_height = $(".slider").attr("box_h") + "px";
		$(".slider").animate({"height": open_height}, {duration: "slow" });
		
		$(".slider_menu").html('<a href="#">Close</a>');
		$(".slider_menu a").click(function() {
			 closeSlider()
			 return false;
			  })
	}
	
	function closeSlider()
	{
		$(".slider").animate({"height": sliderHeight}, {duration: "slow" });
		
		$(".slider_menu").html('<a href="#" >Read More</a>');
		$(".slider_menu a").click(function() { 
		openSlider()
		return false;
		 })
	}

