$(function(){

	//Open all links with rel="external" in new window
	$('a[rel="external"]').click( function() {
			window.open( $(this).attr('href') );
			return false;
    });
	
	if($('body').hasClass('blog')) {
	getTwitters('tweet', { 
				id: 'eyekiller', 
				count: 1, 
				enableLinks: true, 
				ignoreReplies: true, 
				clearContents: true,
				template: '<div>%text%</div> <div><em>Posted </em><a href="http://twitter.com/%user_screen_name%/statuses/%id%/" class="time" rel="external">%time%</a></div>'
			});
	}
});

//functions to be executed inline
var mylib =
{

	image_hover :
	{
		init : function()
		{
			$('.img-hold').hover(function() {
				$(this).children().css({backgroundColor: '#c3c3bf'});
				$(this).children('.fresh').css({backgroundColor: 'transparent'});
			},
			function() {
				$(this).children().css({backgroundColor: '#fff'});
				$(this).children('.fresh').css({backgroundColor: 'transparent'});
			});
		}
	},
	noBorder :
	{
		init : function()
		{
			$('.blog-entry:last .blog-summary').addClass('no-border');
		}
	},
	
	clearValues :
	{
		init : function()
		{
			$(function() {
				swapValues = [];
				$(".f_input").each(function(i){
					swapValues[i] = $(this).val();
					$(this).focus(function(){
						if ($(this).val() == swapValues[i]) {
							$(this).val("");
						}
					}).blur(function(){
						if ($.trim($(this).val()) == "") {
							$(this).val(swapValues[i]);
						}
					});
				});
			});
		}
	},
	
	showreel :
	{
		init : function() {
			$('#showreel-content').hide();
			$('#showreel').addClass('loading');
			
			$.ajax({
				type: "GET",
				url: "xml/showreel.xml",
				dataType: "xml",
				success: function(xml) {
					
					var total = $(xml).find('site').length;
					var randnum = Math.floor(Math.random()*total);
	
					$(xml).find('site').each(function(entryIndex, entry) {
						if(entryIndex === randnum){
							var title = $(this).find('title').text();
							var color = $(this).find('color').text();
							var color2 = $(this).find('color2').text();
							var url = $(this).find('url').text();
							var website = $(this).find('website').text();
							var align = $(this).find('align').text();
							var image = $(this).find('image_src').text();
							var logo = $(this).find('logo_src').text();
							
							$('#head-contact,#head-contact a').css('color',color);
							$('body.home #nav li#home').css('border-bottom','1px solid ' + color);

							$('<div id="info" class="' + align + '"></div>')
							.html('<div class="entry" style="color:' + color2 + '">' + title + '<a href="'+url+'"><br />'+website+'</a></div>')
							.appendTo('#header-content');
							
							$('<div id="logo""></div>')
							.html('<a href="http://www.eyekiller.com/" style="background:url(' + logo + ') no-repeat 0 0;">Eyekiller Website Design</a>')
							.prependTo('#header');
							
							//create new image object to preload image
							var img = new Image();
							//once image has loaded execute this code
							$(img).load(function () {
								//$(this).css('display', 'none'); // .hide() doesn't work in Safari when the element isn't on the DOM already
								$(this).hide();
								$('#showreel').removeClass('loading').append(this);
								$(this).fadeIn(3000);
								}).error(function () {
								// notify the user that the image could not be loaded
							}).attr('src', image);
						}
					});
					
				}//end success function
			});//end ajax function
		}
	}
	
	
}