var carousel_delay = 6000;

var faded = 0;

var hover = 0;


//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//FUNCTIONS
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

function carousel_auto() {
		
	currentimage = $('.show a img').attr('id');
	
	url_ajax = 'resources/ajax/banner.php?random='+(Math.random()*99999)+'&currentimage='+currentimage;
	
	$.ajax({ 
		   
		type: "GET",  
		url: url_ajax,
		dataType: "html",  
		success: function(data) {
			
			if (faded == 0) {
				
				$('#carousel_1').css({'z-index': 2});
				
				$('#carousel_2').css({'z-index': 3});
				
				$('#carousel_2').html(data);
				
				$('#carousel_2 a img').load(function() {
												 
					$('#carousel_2').fadeIn(1500,function() {
					
						$('#carousel_1').fadeOut(0);
						
						$('#carousel_1').removeClass('show');
					
						$('#carousel_2').addClass('show');
						
						faded = 1;
					
						setTimeout('carousel_auto()',carousel_delay);
						
					});
					
					if (hover == 0) {
					
						height = $('#carousel_2 a b').height() + 20;
						
						$('#carousel_2 a b').animate({top: -height},0);	
						
					}
												 
				});
		
				
			
			}
			
			else {
				
			
				$('#carousel_2').css({'z-index': 2});
				
				$('#carousel_1').css({'z-index': 3});
				
				$('#carousel_1').html(data);
				
				$('#carousel_1 a img').load(function() {
												 
					$('#carousel_1').fadeIn(1500,function() {
														   
						$('#carousel_1').addClass('show');
					
						$('#carousel_2').removeClass('show');								   
					
						$('#carousel_2').fadeOut(0);
						
						faded = 0;	
					
						setTimeout('carousel_auto()',carousel_delay);
						
					});
					
					if (hover == 0) {
					
						height = $('#carousel_1 a b').height() + 20;
						
						$('#carousel_1 a b').animate({top: -height},0);
						
					}
												 
				});
				
			}
		
		}
	
	}); //end ajax
	
};

function imagecarousel_auto() {
		
	currentimage = $('.show img').attr('id');
	
	url_ajax = '../../resources/ajax/banner_sub.php?random='+(Math.random()*99999)+'&currentimage='+currentimage+'&banner_page='+banner_page;
	
	$.ajax({ 
		   
		type: "GET",  
		url: url_ajax,
		dataType: "html",  
		success: function(data) {
			
			if (faded == 0) {
				
				$('#imagecarousel_1').css({'z-index': 2});
				
				$('#imagecarousel_2').css({'z-index': 3});
				
				$('#imagecarousel_2').html(data);
				
				$('#imagecarousel_2 img').load(function() {
												 
					$('#imagecarousel_2').fadeIn(1500,function() {
					
						$('#imagecarousel_1').fadeOut(0);
						
						$('#imagecarousel_1').removeClass('show');
					
						$('#imagecarousel_2').addClass('show');
						
						faded = 1;
					
						setTimeout('imagecarousel_auto()',carousel_delay);
						
					});
												 
				});		
			
			}
			
			else {
				
			
				$('#imagecarousel_2').css({'z-index': 2});
				
				$('#imagecarousel_1').css({'z-index': 3});
				
				$('#imagecarousel_1').html(data);
				
				$('#imagecarousel_1 img').load(function() {
												 
					$('#imagecarousel_1').fadeIn(1500,function() {
														   
						$('#imagecarousel_1').addClass('show');
					
						$('#imagecarousel_2').removeClass('show');								   
					
						$('#imagecarousel_2').fadeOut(0);
						
						faded = 0;	
					
						setTimeout('imagecarousel_auto()',carousel_delay);
						
					});
											 
				});
				
			}
		
		}
	
	}); //end ajax
	
};


//////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////                      ///////////////////////////////////////////////
/////////////////////////////////////////    BEGIN ONLOAD      ///////////////////////////////////////////////
/////////////////////////////////////////                      ///////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
$(document).ready(function(){
						   
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

// CAROUSEL

// begin carousel timer

	
if ($('#carousel').length > 0) {
	
	setTimeout('carousel_auto()',carousel_delay);
	
}

if ($('#image_carousel').length > 0) {
	
	setTimeout('imagecarousel_auto()',carousel_delay);
	
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

// title popup

$('#carousel span a b').each(function(){
	
	height = $(this).height() + 20;
	
	$(this).animate({top: -height},0);
												   
});

$('#carousel').hover(function(){
	
	$('#carousel span a b').animate({top: 0},100);
	
	hover = 1;
	
},function(){
	
	$('#carousel span a b').each(function(){
	
		height = $(this).height() + 20;
		
		$(this).animate({top: -height},100);
												   
	});
	
	hover = 0;
									   
});


//////

$('.featured_module span').each(function(){
	
	height = $(this).height() + 20;
	
	$(this).animate({top: -height},0);
												   
});

$('.featured_module').hover(function(){
	
	$(this).children('span').animate({top: 0},100);
	
	
},function(){

	height = $(this).children('span').height() + 20;
		
	$(this).children('span').animate({top: -height},100);
												  				   
});


//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
// MENU COLLAPSE

$('ul.sidebar ul').slideUp(0);

$('ul.sidebar li a.down').parent().next('ul').slideDown(0);

// MENU EXPAND

$('ul.sidebar li a').click(function(){
									
	if ($(this).hasClass('dead')) {
		
		if ($(this).hasClass('down')) {
			
			return false;
		
		} 
		
		else {
									
			$('ul.sidebar li a.down').parent().next('ul').slideUp(200,function(){
			
				$(this).prev().children('a.down').removeClass('down')
														 
			});
										  
			$(this).parent().next('ul').slideDown(200);
			
			$(this).addClass('down');
			
			return false;
			
		}
		
	}
								  
});

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

$('#header .logo').hover(function(){
	
	$(this).children('span').stop(true,true).animate({left: 40, opacity: 0},150,function(){
	
		$(this).animate({left: -40},0);
		
		$(this).animate({left: 0,opacity:1},150);
	
	});
	
								  
},function(){})

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

$("#twitter .inner").getTwitter({
	userName: "noncondesign",
	numTweets: 1,
	loaderText: "<div style=\"text-align:center\">Loading</div>",
	slideIn: false,
	slideDuration: 750,
	showHeading: false,
	headingText: "Latest Tweets",
	showProfileLink: false,
	showTimestamp: true
});

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
});
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////                      ///////////////////////////////////////////////
/////////////////////////////////////////      END ONLOAD      ///////////////////////////////////////////////
/////////////////////////////////////////                      ///////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////


//////////////////////////////////
//////////////////////////////////
//////////////////////////////////
//////////////////////////////////
/////////////TWITTER//////////////
//////////////////////////////////
//////////////////////////////////
//////////////////////////////////

(function($) {
	/*
		jquery.twitter.js v1.5
		Last updated: 08 July 2009

		Created by Damien du Toit
		http://coda.co.za/blog/2008/10/26/jquery-plugin-for-twitter

		Licensed under a Creative Commons Attribution-Non-Commercial 3.0 Unported License
		http://creativecommons.org/licenses/by-nc/3.0/
	*/

	$.fn.getTwitter = function(options) {

		$.fn.getTwitter.defaults = {
			userName: null,
			numTweets: 5,
			loaderText: "Loading tweets...",
			slideIn: true,
			slideDuration: 750,
			showHeading: true,
			headingText: "Latest Tweets",
			showProfileLink: true,
			showTimestamp: true
		};

		var o = $.extend({}, $.fn.getTwitter.defaults, options);

		return this.each(function() {
			var c = $(this);

			// hide container element, remove alternative content, and add class
			c.hide().empty().addClass("twitted");

			// add heading to container element
			if (o.showHeading) {
				c.append("<h2>"+o.headingText+"</h2>");
			}

			// add twitter list to container element
			var twitterListHTML = "<ul id=\"twitter_update_list\"><li></li></ul>";
			c.append(twitterListHTML);

			var tl = $("#twitter_update_list");

			// hide twitter list
			tl.hide();

			// add preLoader to container element
			var preLoaderHTML = $("<p class=\"preLoader\">"+o.loaderText+"</p>");
			c.append(preLoaderHTML);

			// add Twitter profile link to container element
			if (o.showProfileLink) {
				var profileLinkHTML = "<p class=\"profileLink\"><a href=\"http://twitter.com/"+o.userName+"\">http://twitter.com/"+o.userName+"</a></p>";
				c.append(profileLinkHTML);
			}

			// show container element
			c.show();

			$.getScript("http://twitter.com/javascripts/blogger.js");
			$.getScript("http://twitter.com/statuses/user_timeline/"+o.userName+".json?callback=twitterCallback2&count="+o.numTweets, function() {
				// remove preLoader from container element
				$(preLoaderHTML).remove();

				// remove timestamp and move to title of list item
				if (!o.showTimestamp) {
					tl.find("li").each(function() {
						var timestampHTML = $(this).children("a");
						var timestamp = timestampHTML.html();
						timestampHTML.remove();
						$(this).attr("title", timestamp);
					});
				}

				// show twitter list
				if (o.slideIn) {
					// a fix for the jQuery slide effect
					// Hat-tip: http://blog.pengoworks.com/index.cfm/2009/4/21/Fixing-jQuerys-slideDown-effect-ie-Jumpy-Animation
					var tlHeight = tl.data("originalHeight");

					// get the original height
					if (!tlHeight) {
						tlHeight = tl.show().height();
						tl.data("originalHeight", tlHeight);
						tl.hide().css({height: 0});
					}

					tl.show().animate({height: tlHeight}, o.slideDuration);
				}
				else {
					tl.show();
				}

				// add unique class to first list item
				tl.find("li:first").addClass("firstTweet");

				// add unique class to last list item
				tl.find("li:last").addClass("lastTweet");
			});
		});
	};
})(jQuery);

//////////////////////////////////
//////////////////////////////////
//////////////////////////////////
//////////////////////////////////
//////////////////////////////////
//////////////////////////////////
//////////////////////////////////
//////////////////////////////////
