// JavaScript Document
	
var client_height;
var hasMapDesc; /* global variable for news that have description for map */
var isCompletedAnim; /* check that the animation is completed before user can click another menu*/

var isCompletedAnim=true;
var differentAnim=true; /* check that you clicked twice or more the same menu */

var prevSelectedContent;

var bgFolderImages="images/bgs/"; /* the folder that contains all background images of your site */

prevSelectedContent='home-page'; /* the default div id that works as your home page. change it by writing your own div id for your home page*/

/* cufon has problems with IE7 so we use this condition in order not to initialize cufon actions if the user has IE7*/
if (!ie7)
{
	Cufon.replace('.main_content h1', { textShadow: '#0a0327 0 1px 1px' });
	Cufon.replace('.main_content h2', { textShadow: '#0a0327 0 1px 1px' });
	Cufon.replace('.main_content h3', { textShadow: '#0a0327 0 1px 1px' });
	Cufon.replace('.main_content h4', { textShadow: '#0a0327 0 1px 1px' });
	Cufon.replace('.main_content h5', { textShadow: '#0a0327 0 1px 0px' });
	Cufon.replace('.main_content h6', { textShadow: '#0a0327 0 1px 0px' }); 
	Cufon.replace('#home-page .f_box .top h2', { textShadow: '#c5c5d4 0 1px 1px' });
	Cufon.replace('.sidebar h3', { textShadow: '#0a0327 0 1px 0px' });
	Cufon.replace('.overlay h3', { textShadow: '#0a0327 0 1px 0px' });
	Cufon.replace('.t_header');
	Cufon.replace('#videoDivPlaylist h4', { textShadow: '#0a0327 0 1px 1px' });
	Cufon.replace('#footer .wrapper h3', { textShadow: '#0a0327 0 1px 0px' });
}

/* -------- INIT PROCESS -------- */
$(document).ready(function() {
	
	/* load nivo slider with the option below */
	/*IE7 ISSUE*/
	if (ie7) {
		
		$('#nivo-slider').nivoSlider({
			effect:'random', //Specify sets like: 'fold,fade,sliceDown'
			slices:15,
			animSpeed:500,
			pauseTime:8000,
			startSlide:1, //Set starting Slide (0 index)
			directionNav:true, //Next & Prev
			directionNavHide:false, //Only show on hover
			controlNav:true, //1,2,3...
			controlNavThumbs:false, //Use thumbnails for Control Nav
			controlNavThumbsFromRel:false, //Use image rel for thumbs
			controlNavThumbsSearch: '.jpg', //Replace this with...
			controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
			keyboardNav:true, //Use left & right arrows
			pauseOnHover:true, //Stop animation while hovering
			manualAdvance:false, //Force manual transitions
			captionOpacity:1, //Universal caption opacity
			beforeChange: function(){},
			afterChange: function(){},
			slideshowEnd: function(){} //Triggers after all slides have been shown
		});
			
		setTimeout("document.getElementById('first_nivo_link').click();",0);
	}
	else
	{
		$('#nivo-slider').nivoSlider({
			effect:'random', //Specify sets like: 'fold,fade,sliceDown'
			slices:15,
			animSpeed:500,
			pauseTime:8000,
			startSlide:0, //Set starting Slide (0 index)
			directionNav:true, //Next & Prev
			directionNavHide:false, //Only show on hover
			controlNav:true, //1,2,3...
			controlNavThumbs:false, //Use thumbnails for Control Nav
			controlNavThumbsFromRel:false, //Use image rel for thumbs
			controlNavThumbsSearch: '.jpg', //Replace this with...
			controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
			keyboardNav:true, //Use left & right arrows
			pauseOnHover:true, //Stop animation while hovering
			manualAdvance:false, //Force manual transitions
			captionOpacity:1, //Universal caption opacity
			beforeChange: function(){},
			afterChange: function(){},
			slideshowEnd: function(){} //Triggers after all slides have been shown
		});
	}

	/* this is the initialization for the projects of portfolio. We seperated action in IE7 because of compatibility problems with overlay */
	if (!ie7) {
		$("a[rel]").overlay({ effect: 'drop', mask: '#0e4860' });
	}
	else {
		$("a[rel]").overlay({ 
			effect: 'drop', 
			mask: '#0e4860',
			closeOnClick: false,
			onBeforeLoad : function() {
				var that = this					
				$(this.getOverlay()).remove().appendTo("body");
				$(".close", this.getOverlay()).click(function(e){
					that.close();
				});
			}
		});
	}
	
	/* we calculate the height of the screen */
	if (typeof window.innerWidth != 'undefined')
	{
		client_height = window.innerHeight
	}
	else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth !='undefined' && document.documentElement.clientWidth != 0)
	{
		client_height = document.documentElement.clientHeight
	}
	
	/* if you have a link that has class returnTop it will make an animation while taking you back on top of the site */
	$('.returnTop').click(function(){
		$('html, body').animate({scrollTop:0}, 'slow');
	});
	
	/* for each div that we have in our site we set display:none except the one that we use as our homepage */
	$("#about").css({'display' : 'none'});
	$("#typography").css({'display' : 'none'});
	$("#portfolio").css({'display' : 'none'});
	$("#news").css({'display' : 'none'});
	$("#contact").css({'display' : 'none'});
	$(".selected-news").css({'display' : 'none'}); /* this is a class and not ID. its for your news */

	/* this is the initialization for the twitter feeds. change "themeforest" with your twitter name */
	$('#twitterNews').twit('BarneyAndCocos', {
	  limit: 2
	});
	
	/* the below lines are very critical for the site to have stable height at its home page */
	//calculate selected div's height
	innerHeight=$("#" + prevSelectedContent).height(); 
				
	//calculate headers height
	innerHeightHeader=$("#header").height(); 
			
	//calucate main content height
	innerMainHeight=client_height - innerHeightHeader;
				
	if (innerHeight<innerMainHeight)
	{
		innerHeight=innerMainHeight;	
	}
	
	$("#" + prevSelectedContent).css({"height": innerHeight + "px"});

	$('#contact_form .submit').bind('click', function() {
		
		var name=$('#contact_form .name').val();  
		var email=$('#contact_form .email').val();  
		var message=$('#contact_form .message').val();  
		
		if (name=='enter your name * :')
		{
			name='';	
		}
		
		if (email=='enter your e-mail address * :')
		{
			email='';	
		}
		
		if (message=='enter your message :')
		{
			message='';	
		}
		
		$.ajax({
		   type: "POST",
		   url: "modules/send_email.php",
		   data: "fullname=" + name + "&email=" + email + "&message=" + message,
		   success: function(msg){
			 alert(msg);
		   }
		});
	});
});


/* -------- END INIT PROCESS -------- */

/* -------- OVERLAY --------*/

// create custom animation algorithm for jQuery called "drop" 
$.easing.drop = function (x, t, b, c, d) {
	return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
};
 
 
// loading animation
$.tools.overlay.addEffect("drop", function(css, done) { 
   
   // use Overlay API to gain access to crucial elements
   var conf = this.getConf(),
       overlay = this.getOverlay();           
   
   // determine initial position for the overlay
   if (conf.fixed)  {
      css.position = 'fixed';
   } else {
      css.top += $(window).scrollTop();
      css.left += $(window).scrollLeft();
      css.position = 'absolute';
   } 
   
   var rel_id=$(overlay).attr('class');

   if (rel_id=='overlay')
   {
	    // position the overlay and show it
		overlay.css(css).show();
   
   		// begin animating with our custom easing
   		overlay.animate({ top: '+=55',  opacity: 1,  width: '+=20'}, 400, 'drop', done);
   }
   else
   {
		$("#exposeMask").css( {'display':'none'});
   }
   /* closing animation */
   }, function(done) {
      this.getOverlay().animate({top:'-=55', opacity:0, width:'-=20'}, 300, 'drop', function() {
         $(this).hide();
         done.call();      
      });
   }
);
/* -------- END OVERLAY ------*/

/* -------- FOOTER -------- */
$(function() {
	
	/* this function toggles footer to show or hide footer elements */
	$("#f_btn").toggle ( 
	    function() {
		    $("div#footer").animate({"bottom": "0"}, "slow", "linear", function () {
			    $("#f_btn").css({'background-image' : 'url(images/f_btn_close.png)', 'top' : '18px', 'left' : '11px'});
			});
				
			return false;
		},
		function() {
			$("div#footer").animate({"bottom": "-296px"}, "slow", "linear", function () {
				$("#f_btn").css({'background-image' : 'url(images/f_btn.png)', 'top' : '23px', 'left' : '5px'});
			});
				
			return false;
		});	   
	}
);
/* -------- END FOOTER -------- */

/* -------- CHANGE CONTENT -------- */

function changeContent(divID,bgID) {
	var clientsHeight;
	
	$('html, body').animate({scrollTop:0}, 'slow');
	
	if (divID!=prevSelectedContent) /* if the selected div is not the same as the previous selected div */
	{
		differentAnim=true;	
	}
	else
	{
		differentAnim=false;	
	}
	
	if ((isCompletedAnim) && (differentAnim)) /* if the animation of the selected div is finished and the selected div is different than the previous selected */
	{
		isCompletedAnim=false;
		
		if (divID!='indi-news') /* if the selected div is not the one that contains the individual news */
		{
			if ($('#' + divID).is(':visible')) { /* if the selected div is already visible */
				
				if (divID.indexOf('selected-news')!='-1') /* if the selected div is the one that contains all the elements for the individual news */ /* if the selected div is the one that contains all the elements for the individual news */
				{
					if (ie7) /* we made some changed only for IE7 */
					{
						setTimeout("$('#mapCanvas').css({'top' : '0'});	",1);
						setTimeout("$('#mapCanvasDesc').css({'top' : '0','left' : '0px'});	",1);
						setTimeout("$('#mapCanvasDesc').css({'top' : '0','left' : '7px'});	",1);
					}
					
					isCompletedAnim=true;
				}
			}
			else {
				// it's not visible so do animation
				
				//check if selected div is already appended to body. If yes, append it to main container
				if($("#" + divID).hasClass('appendedDivElement')) {
					$("#content").append($("#" + divID));
				}
				
				//calculate selected div's height
				innerHeight=$("#" + divID).height(); 
				
				//calculate headers height
				innerHeightHeader=$("#header").height(); 
			
				//calucate main content height
				innerMainHeight=client_height - innerHeightHeader;
				
				if (innerHeight<innerMainHeight)
				{
					innerHeight=innerMainHeight;	
				}
				
				//change attributes of selected div
				$("#" + divID).css({'height' : '0px', 'display' : 'block'});
				$("li." + divID + "-menu").addClass('current');
				
				//append on body the current div
				$("#container_body").append($("#" + prevSelectedContent));
				
				$("li." + prevSelectedContent + "-menu").removeClass('current');
				
				$("#" + divID).animate({"height": innerHeight + "px"}, 3000, function () {
					$("#" + prevSelectedContent).css({'display' : 'none'});
					$("#" + prevSelectedContent).addClass('appendedDivElement');
	
					prevSelectedContent=divID;
					
					//animate change of height
					changeBackgroundImage(bgID)
					
					isCompletedAnim=true;
					
					if (divID.indexOf('selected-news')!='-1') /* if the selected div is the one that contains all the elements for the individual news */ /* if the selected div is the one that contains the individual news */
					{
						
						innerHeightSelectedNews=$("#" + divID + " .main").height(); /* we calculate the height of the selected news */
						innerHeightSidebar=$("#" + divID + " .sidebar").height(); /* we calculate the height of the sidebar */
						innerHeightHeader=$("#header").height(); /* we calculate the height of the header */
					
						innerHeight=parseInt(innerHeightSelectedNews) + parseInt(innerHeightHeader) + 50; /* we calculate the total height of the site */
						
						if (innerHeightSelectedNews>innerHeightSidebar) { /* if the height of the selected news is higher than the sitebar */
							if (innerHeight<client_height) { /* if the height of the selected news is lower that the height of the screen */
								innerHeight=client_height; /* set the height of the selected news equal to the height of the screen */
							}
						}
						else { /* if the height of the selected news is lower than the sitebar */
							innerHeight=parseInt(innerHeightSidebar) + parseInt(innerHeightHeader) + 50;  /* set the height of the selected news equal to the height of the sitebar + header + 50 more pixels for security reasons */
						}

						if (innerHeight<client_height) {
												
							if ((!$.browser.mozilla) && (!$.browser.msie)) {
								innerHeight=parseInt(client_height);
							}
							else
							{
								innerHeight=parseInt(client_height);
							}
						}
						
						setTimeout("$('#" + divID + " ').css({'height' : '" + innerHeight + "px'});	",1);
	
						if (ie7)
						{
							setTimeout("$('#mapCanvas').css({'top' : '0'});	",1);
							setTimeout("$('#mapCanvasDesc').css({'top' : '0','left' : '0px'});	",1);
							setTimeout("$('#mapCanvasDesc').css({'top' : '0','left' : '7px'});	",1);
						}
					}
	
				});
				
			}
		}
		else
		{
			isCompletedAnim=true;	
		}
	}
	else
	{
		if (divID!=prevSelectedContent)
		{
			differentAnim=true;
		}
	}
}
/* -------- END CHANGE CONTENT -------- */

/*--------- CHANGE BACKGROUND IMAGE -----------*/
//Declare global variable in otder to use it as an array containing the background images

var bgIndiCategories=Array();

/* 
   Fill the array with the background images.
   In order to add another background image please follow the format below:
   
   bgIndiCategories[UNIQUE_NUMBER]="NAME OF BACKGROUND IMAGE";
   
   For example if you have 4 background images as above and you want to add another one:
   
   bgIndiCategories[5]="YOUR_IMAGE_NAME";
*/

bgIndiCategories[1]="1.jpg";
bgIndiCategories[2]="2.jpg";
bgIndiCategories[3]="3.jpg";
bgIndiCategories[4]="4.jpg";
bgIndiCategories[5]="5.jpg";
bgIndiCategories[6]="2.jpg";


/* 
   This function is for changing the background image. It takes a number as parameter.
   This number is the unique number you used above. For example if you want to load
   the 3.jpg background image you must call this function:
   
   <a href='javascript:void(0)' onclick='changeBackgroundImage('3')>YOUR LINK</a>   
*/
function changeBackgroundImage(bgID)
{
	$('#bgImage').fadeTo(500, 0.3 , function () {
		$('#bgImage').attr("src", bgFolderImages + bgIndiCategories[bgID]);
		$('#bgImage').fadeTo(500,1);
	});
	
	return true;
}
/*--------- END CHANGE BACKGROUND IMAGE -----------*/
