$(document).ready(function(){
	
	nav.init({
		mainmenuid: "smoothmenu1", //menu DIV id
		orientation: 'h', //Horizontal or vertical menu: Set to "h" or "v"
		classname: 'nav', //class added to menu's outer DIV
		//customtheme: ["#1c5a80", "#18374a"],
		contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"]
	});

	$('#slideshow').cycle({ 
		fx:     'fade', 
		speed:   2000, 
		timeout: 5000, 
		next:   '#next',
        prev:   '#prev',
		before:  onBefore, 
		after:   onAfter,
		cleartype:  1
	 });
	
	function onBefore() { 
		$('#output').animate({  
			bottom: "-40px"
		}, 500 );
		$('#output').html("");
	}
	
	function onAfter(curr,next,opts) { 
		if (this.alt != '') {
			//alert(this.alt);
			$('#output').animate({ 
				bottom: "0"
			}, 800 );
			$('#output').html('<p>' + this.alt + '</p>'); 

		}
		if (opts.slideCount==1) {
			$('#slideshow').cycle('stop');
			return false;
		}
	}
	$('#pause').click(function() { $('#contentGallery').cycle('pause'); return false; });
    $('#play').click(function() { $('#contentGallery').cycle('resume'); return false; });

	

	$("#slider div.scrollable").scrollable({
		size: 1,
		next: ".next",
		prev: ".prev",
		clickable: false,
		items: '.item',
		speed: 500		
	}).autoscroll({
		autoplay: true,
		interval: 7000
	}).circular(); 

   $("#projectImages .scrollable").scrollable({ 
		vertical:true,  
		size: 6,
		next: ".next",
		prev: ".prev"
	});        
	  
	  //Styles
	  $("#currentUser ul li:last").css('border-bottom','1px solid #e7e7e8');
	  $(".directors:even").css('margin-left','0');
	  //$(".projectsGrid:first").css('margin','0');
	  $(".projectList:even").css('margin-left','0');
	  
	  target = $('#leftSidebarMenu').size();
	  if (target == 0) {
		$('#leftSidebar').css('display','none');
		$('#middleContentNarrow').width(700);
	  }
	  
	  
	  //Tooltips
	  $(".tooltipTrigger").tooltip({
		tip : '.tooltip',
		effect: 'slide',
		position: "top right", 
	    offset: [10, -50]
	  }); 
		$(".projectsGrid").tooltip({
		tip : '.tooltip',
		effect: 'slide',
		position: "bottom center", 
	    offset: [-20, 0]
	  }); 
	  
	  $('.backToTop').click(function(){
               $('html, body').animate({scrollTop:0}, 'slow'); 
               return false;
      }); 

	  
	  
}); //Close document.ready

$(window).bind("load", function() {								
	$('.loading').hide();
	$('#slideshowWrapper').fadeIn();
});

/*------- Validation additonal methods --------------------------------------------------*/

function sumbitForm(formId) {
	 data = $('#'+formId).serialize();
	 formAction = $('#'+formId).attr("action");
	 url = 'assets/snippets/campaignMonitor/proxy.php';
	 final = data + "&action=" + formAction;
     $.ajax({
      type: "POST",    
      url: url,
      data: final,
      success: function(msg){
        $('#newsletter_form').html("<span class='error'>Thank you for subscribing to the Tender Team newsletter.<br />You'll receive the first edition by email soon.</span>");
		$.get('ezine-conversion', function(data) {
			$('#newsletter_form').append(data);
		});	
      }
    });
    return false;
}
/*------- Equal hights ---------------------------------------------------------*/
function equalHeight(group) {
	tallest = 0;
	group.each(function() {
		thisHeight = $(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	group.height(tallest);
}
/*------- Toggle animation (open - close) --------------------------------------*/
(function($) {
	$.fn.animPanel = function(options) {
		var opts = $.extend({}, $.fn.animPanel.defaults, options);
		return this.each(function() {
			$this = $(this);
			var o = $.meta ? $.extend({}, opts, $this.data()) : opts;				
			$this.toggle(function() {
				$(o.target).animate({ top: o.topStart }, 300, "easeOutBounce", function() { 
					$(o.target).find('#trigger').html(o.textOpen);
				});						   
			},function() {
				$(o.target).animate({ top: o.topEnd }, 300, "easeOutBounce", function() { 
					$('#topPanelOne ul li ul:visible').slideUp();	
					$(o.target).find('#trigger').html(o.textClose);
				});						   	
			})	
			
		});
	};
})(jQuery);
/*------ Easing animations -----------------------------------------------------*/
(function($) {
	$.easing.custom = function (x, t, b, c, d) { 
		var s = 1.70158;  
		if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b; 
		return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b; 
	}
	$.easing.easeOutExpo = function (x, t, b, c, d) {
		return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
	};
	$.easing.easeOutBounce = function (x, t, b, c, d) {
		if ((t/=d) < (1/2.75)) {
			return c*(7.5625*t*t) + b;
		} else if (t < (2/2.75)) {
			return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
		} else if (t < (2.5/2.75)) {
			return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
		} else {
			return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
		}
	};
})(jQuery);
/*----- Custom alert popup -----------------------------------------------------*/
function my_alert(url) {
	$('body').append('<div id="alert"><span class="close">Close</span></div>');
	$("#alert").load(url);
	$("#alert").overlay({ 
		top: 200, 
		expose: { 
			color: '#6c98b9', 
			loadSpeed: 500, 
			opacity: 0.6,
			effect: 'apple'			
		}, 
		closeOnClick: false,
		api: true 
	}).load();
}

