function showTweets(elem, username, number)
	{
		//var html = '<ul id="tweets" class="frontcarousel jcarousel-skin-tango">';
 		var html = '<ul id="tweets">';
 
 
	var tweetFeed = 'http://twitter.com/status/user_timeline/' + username + '.json?count=' + number + '&callback=?'
		$.getJSON(tweetFeed, function(d)
		{
 
 
			$.each(d, function(i,item)
			{
				/* Some extra code to search for links and format them accordingly */
				item.text = item.text+' '; // This makes life easier searching for the url length if at the end
				var urlstart = item.text.indexOf('http://'); // Searching for the start
				var urlend = item.text.indexOf(' ',urlstart); // ...and the end
				var urllen = urlend-urlstart; // Now the length
				var url = item.text.substr(urlstart,urllen); // Extract the url
				var formattedurl = '<a href="'+url+'">'+url+'</a>'; // Reformat to a link
				//item.text = item.text.replace(url, formattedurl); // Replace the link with relevant html
				
				html+='<li>'+item.text+'</li>';
			})
			html+="</ul>";
			
			
			elem.children().fadeOut('fast',function() {
				
				elem.append(html);
			})
		})
	}
 
$(document).ready(function(){

// Nifty nifty
$(".lang_confirm").colorbox({width:"400px", height:"300px", inline:true, href:"#nifty_box"});

// tabs 
  switch_tabs($('.defaulttab'));

  $('.tabs a').click(function(){
    switch_tabs($(this));
  });
  
function switch_tabs(obj)
{

  $('.tab-content').fadeOut('fast');
  $('.tabs a').removeClass("selected");
  var id = obj.attr("rel");
 
  $('#'+id).fadeIn('fast');
  obj.addClass("selected");
}


// twitter

        $("#tweet").tweet({
            username: "storm_fm",
            count: 1,
            loading_text: "loading tweets...",
            template: function(i){return i["text"]},
            refresh_interval: 60
        });


/*$(function() {
			$('#error').remove();
			$('#preload').show();
			showTweets($('#tweets'), 'storm_fm', 1)
			
});*/

	//Set Default State of each portfolio piece
	$(".paging").show();
	$(".paging a:first").addClass("active");
	
		
	//Get size of images, how many there are, then determin the size of the image reel.
	/*var imageWidth = $(".window").width();*/
	var imageWidth = 960;
	var imageSum = $(".image_reel img").size();
	var imageReelWidth = imageWidth * imageSum;
	
	//Adjust the image reel to its new size
	$(".image_reel").css({'width' : imageReelWidth});
	
	//Paging + Slider Function
	rotate = function(){	
		var triggerID = $active.attr("rel") - 1; //Get number of times to slide
		var image_reelPosition = triggerID * imageWidth; //Determines the distance the image reel needs to slide
 
		$(".paging a").removeClass('active'); //Remove all active class
		$active.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)
		
		//Slider Animation
		$(".image_reel").animate({ 
			left: -image_reelPosition
		}, 500 );
		
	}; 
	
	//Rotation + Timing Event
	rotateSwitch = function(){		
		play = setInterval(function(){ //Set timer - this will repeat itself every 3 seconds
			$active = $('.paging a.active').next();
			if ( $active.length === 0) { //If paging reaches the end...
				$active = $('.paging a:first'); //go back to first
			}
			rotate(); //Trigger the paging and slider function
		}, 5000); //Timer speed in milliseconds (3 seconds)
	};
	
	rotateSwitch(); //Run function on launch
	
	//On Hover
	$(".image_reel a").hover(function() {
		clearInterval(play); //Stop the rotation
	}, function() {
		rotateSwitch(); //Resume rotation
	});	
	
	//On Click
	$(".paging a").click(function() {	
		$active = $(this); //Activate the clicked paging
		//Reset Timer
		clearInterval(play); //Stop the rotation
		rotate(); //Trigger rotation immediately
		rotateSwitch(); // Resume rotation
		return false; //Prevent browser jump to link anchor
				
	});
  
$("#contact-toggle").click(function(){
		$("#niftyform").slideToggle("slow");
		$(this).toggleClass("contact-active");
		return false;
	});
  

$("#contactLink").click(function(){
	if ($("#contactForm").is(":hidden")){
    	$("#contactForm").slideDown("slow");
    }
    else{
       $("#contactForm").slideUp("slow");
    }	
});

/* Carousel */
jQuery('.frontcarousel').jcarousel({
	vertical: true

});
    
	$('#slider').nivoSlider({
		effect:'sliceDown', //Specify sets like: 'fold,fade,sliceDown'
		slices:20,
		animSpeed:500, //Slide transition speed
		pauseTime:6000,
		startSlide:0, //Set starting Slide (0 index)
		directionNav:true, //Next & Prev
		directionNavHide:false, //Only show on hover
		controlNav:false, //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
	});

});
 // onload ends


// closeform
function closeForm(){
  $("#messageSent").show("slow");
      setTimeout('$("#messageSent").hide();$("#contactForm").slideUp("slow")', 4000);
}

/* Webplayer launch */

function stormPlayer(url) {

	if(url)
	{
		var launch = './live/index.php?url='+url;
	}
	else{
		var launch = './live/index.php';
	}
	
	window.open(launch, 'stormPlayer', 'width=500,height=230,toolbar=0,resizable=0,scrollbars=0,status=0');
}

/* Content loader */

function loadToDiv(source,target) {
	// To prevent content caching
	var uniq = new Date();
	// To prevent harmful code injection
	var baseURL = location.href;
    var rootURL = baseURL.substring(0, baseURL.indexOf('/', 7));
	// Format the source
	var source_timed = rootURL + source + "?" + uniq.getTime();
	
	$(target).load(source_timed);
} 

/* Nifty Form */

  $(function(){
    $('#contact').contactable({
      subject: 'A Feeback Message'
    });
  });

