//initiate dropdown menu
jQuery(function(){
	jQuery('ul.nav').superfish();
});

// On page LOAD
$(function() { 

	//show / hide default input values on select 
	var active_color = '#000000'; // Colour of user provided text
	var inactive_color = '#1b1b1b'; // Colour of default text
	$("input.default").css("color", inactive_color);
	var default_values = new Array();
	$("input.default").focus(function() {
		if (!default_values[this.id]) {
			default_values[this.id] = this.value;
		}
		if (this.value == default_values[this.id]) {
			this.value = '';
			this.style.color = active_color;
		}
		$(this).blur(function() {
			if (this.value == '') {
				this.style.color = inactive_color;
				this.value = default_values[this.id];
			}
		});
	});

	//hover over news blocks
	/*
	$('#content .block a.news').hover( function() {
		$(this).css({'background':'none'});
		$(this).parent().find('h3').addClass('highlight').removeClass('lowlight');
		$(this).parent().find('p.author').addClass('highlight').removeClass('lowlight');
		$(this).parent().find('p.date').addClass('highlight').removeClass('lowlight');
	}, 
	function (){
		$(this).css({'background':'transparent url("http://www.theodin.co.uk/tools/dropbox/shutter.png") repeat'});	
		$(this).parent().find('h3').addClass('lowlight').removeClass('highlight');
		$(this).parent().find('p.author').addClass('lowlight').removeClass('highlight');
		$(this).parent().find('p.date').addClass('lowlight').removeClass('highlight');
	});
	
	//apply a hover for the titles of news blocks
	$('#content .lowlight').hover( function() {
		$(this).parent().find('a.news').css({'background':'none'});
		$(this).parent().find('h3').addClass('highlight').removeClass('lowlight');
		$(this).parent().find('p.author').addClass('highlight').removeClass('lowlight');
		$(this).parent().find('p.date').addClass('highlight').removeClass('lowlight');
	}, 
	function (){
		$(this).parent().find('a.news').css({'background':'transparent url("http://www.theodin.co.uk/tools/dropbox/shutter.png") repeat'});
		$(this).parent().find('h3').addClass('lowlight').removeClass('highlight');
		$(this).parent().find('p.author').addClass('lowlight').removeClass('highlight');
		$(this).parent().find('p.date').addClass('lowlight').removeClass('highlight');
	});	
	
	//initiate the flickr feed
	$('#flickr').flickrush({
		limit:4,
		id:'44499772@N06',
		random:true
	}); 
	*/
	
	//initiate the twitter feed 
	//$('#tweet').tweetable({username: 'smashingmag', limit: 1});
	
	//initiate tool tip plugin
	//$('.tip').tipsy({gravity: 'n'});
 
	//initiate the fancybox lightbox
	//$("a.fancy").fancybox();
	 

	// TeamAlona.com ---------------------------------------------------
	// Make dates pretty
	makeTsPretty();

	// Show News Image Content if there are any
	showImgContent();	
});


function pageLoadComments(userSrcId)
{
	// Load comments
	$('#comments-list').load("/comments/get/" + userSrcId,
							 function(){
								makeTsPretty(); 
							 });
	
	
}



function alertMsg(userStatus,userMsg,onClose)
{
	$('#alertMsgPanel h1').html(userStatus);
	$('#alertMsgPanel p').html(userMsg);
	$.fancybox(
		{
			'href':'#alertMsgPanel',
			'centerOnScroll': true,
        	'autoDimensions': false,
			'width'         : 375,
			'height'        : 'auto',
			'transitionIn'	: 'fade',
			'transitionOut'	: 'fade',
			'overlayColor'	: 'black',
			'overlayOpacity': 0.6,
			'onClosed' : onClose
		}
	);		
}


function makeTsPretty()
{
	$('.tsPretty').each(function(){
		$(this).html(prettyDate($(this).attr('ts')));
	});
}


/* News Image Promotion
------------------------------------------------------------------------------------------------- */
function showImgContent() {
	
	// Offset coordinates for placing of background image
	var bgPosH="-5px -60px";
	var bgPosV="-5px -100px";

	// Iterate through all the imgCanvas nodes making the specified pix as the background-image
	$(".imgCanvas").each(function(n){
	
		// Apply the background image
		$(this).css("background-image","url('" + $(this).attr("pix") + "')");
		
		
		// Do the following only if a pixPos was specified
		if($(this).attr("pixPos"))
		{
			// Apply the right background position
			switch($(this).attr("pixPos"))
			{
				case "h":
					$(this).css("background-position",bgPosH);
				break;
				case "v":
					$(this).css("background-position",bgPosV);
				break;
			}			
		}
		
		// Otherwise do the specified positioning
		else
		{
			var bgPosUser="-" + $(this).attr("pixX1") + "px -" + $(this).attr("pixY1") + "px";
			$(this).css("background-position",bgPosUser);
			//alert(bgPosUser);		
		}
	});
}






/*
	Cookie Functions
	------------------------------------------------------------------------------------------------------------- */
function cookieMake(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function cookieRead(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function cookieEat(name) {
	cookieMake(name,"",-1);
}
/*
	------------------------------------------------------------------------------------------------------------- 
	// Cookie Functions */
