var magicElements=Array("we-design","photoshop-flash","design-link","valid-css","wai","w3c-link","code","code-link","we-master","facebook","wordpress","drupal","etc","api-link","your-rank","seo-link");
var iTimer;
var iDuration=3000;
var portfolioPosition=0;
var _promo_elements= new Array();
$(document).ready(function(){
getPromoElements();
	//mouse over for promo-menu
	$("a.promo-menu ").hover(function() { //When trigger is clicked...
		//get the current position of the section
		_contentTop=Math.abs(parseInt(document.getElementById("section-"+this.id).style.top))
		if(!_contentTop){
			_contentTop=0; //defaults to 0
		}
		
		animate_to=320; // the height till which it should be animated
		if(_contentTop==0 || _contentTop==animate_to){ //only animate if at top or bottom not in middle
			$(this).parent().find("div.promo-content").toggle('slow'); 
		}else{
			return false // no animation if in midle
		}
		
		if(_contentTop==animate_to){ //if at top animate to bottom
			animate_to=0;
		}
		
		 $("#section-"+this.id).animate({  // jquery magic happens here slides to top or bottom
			top:"-"+animate_to+"px"}, 520)
 //window.setTimeout("checkForHint()",900);

	});
	
	// event for promo texts taht appears on image
	$("a.promo-text ").hover(function() {
			$(this).find("img").fadeIn(); //jquery fadeToggle
			
			// the magic if user doesn't move mouse for some period let the animation happen on its own
			if(iTimer){
				window.clearInterval(iTimer);
				iDuration=1500;
			}
			iTimer=window.setInterval("doMagic()",1000)
			
	 })
	//$("a.promo-text").find("img").fadeToggle();
	
	$('#myTextarea').elastic();
	
	//on mouse hover more link visible
	$(".related-text").hover(function() { 
		slidingPosition=($(this).parent().find("a.morelink").css('height')=='14px' || $(this).parent().find("a.morelink").css('height')=='auto')
		if(slidingPosition){
			$(this).parent().find("a.morelink").slideDown('slow').show();
		}
		
		$(this).parent().hover(function() {
		}, function(){
			if(slidingPosition){
				$(this).parent().find("a.morelink").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up
			}
		});
	});
	$(".related-text").click(function() { 
		document.location.href=$(this).parent().find("a.morelink").attr('href');
	});
	
	$("a.morelink").fadeOut('slow');
	//start portfolio animation
	//iTimer2=window.setInterval("animatePortfolio()",10)
});

//extend jquery so that we can fade toggle
jQuery.fn.fadeToggle = function(speed, easing, callback) {
   return this.animate({opacity: 'toggle'}, speed, easing, callback);

};

// picks the random element for the animation on its own
function doMagic(){
	_random=Math.floor(Math.random()*magicElements.length)
	_doMagic(magicElements[_random])
	iDuration=1000
}

//animate the randomly picked element
function _doMagic(magicFor){
	$("#"+magicFor).find("img").fadeToggle();
}

function animatePortfolio(){
	if (portfolioPosition==0){
		
	}portfolioPosition++;
	
	if(portfolioPosition==320){
		portfolioPosition=0
	}
	document.getElementById("portfolio").style.backgroundPosition="0px -"+portfolioPosition+"px"
}

function getPromoElements(){
i=0;
	jQuery("#promo .promo-content").each(function(){
				   _promo_elements[i]=this
i++; 
						  })

}
/*
function checkForHint(){
	
show_hint=false;
 for(i=0;i < _promo_elements.length;i++){
	 
    if(_promo_elements[i].style.display=='block'){
        //is hint displayed
         show_hint=true; 
        //if(document.getElementById('theHint').style.display=="none"){
	//document.getElementById('theHint').style.visibility='visible'
	 //$("#theHint").show("slow")
document.getElementById('theHint').style.display='block'
          $("#theHint").fadeIn("slow")
        //}
    }
 }

  if(!show_hint){
    $("#theHint").fadeOut("slow")
 $("#theHint span").hide();
  }
}*/
