/*
 * jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/
 *
 * Uses the built in easing capabilities added In jQuery 1.1
 * to offer multiple easing options
 *
 * TERMS OF USE - jQuery Easing
 * 
 * Open source under the BSD License. 
 * 
 * Copyright Â© 2008 George McGinley Smith
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 * 
 * Redistributions of source code must retain the above copyright notice, this list of 
 * conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice, this list 
 * of conditions and the following disclaimer in the documentation and/or other materials 
 * provided with the distribution.
 * 
 * Neither the name of the author nor the names of contributors may be used to endorse 
 * or promote products derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 *  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
 * OF THE POSSIBILITY OF SUCH DAMAGE. 
 *
*/

// t: current time, b: begInnIng value, c: change In value, d: duration
jQuery.easing['jswing'] = jQuery.easing['swing'];

jQuery.extend( jQuery.easing,
{
	def: 'easeOutQuad',
	swing: function (x, t, b, c, d) {
		//alert(jQuery.easing.default);
		return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
	},
	easeInQuad: function (x, t, b, c, d) {
		return c*(t/=d)*t + b;
	},
	easeOutQuad: function (x, t, b, c, d) {
		return -c *(t/=d)*(t-2) + b;
	},
	easeInOutQuad: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t + b;
		return -c/2 * ((--t)*(t-2) - 1) + b;
	},
	easeInCubic: function (x, t, b, c, d) {
		return c*(t/=d)*t*t + b;
	},
	easeOutCubic: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t + 1) + b;
	},
	easeInOutCubic: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t + b;
		return c/2*((t-=2)*t*t + 2) + b;
	},
	easeInQuart: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t + b;
	},
	easeOutQuart: function (x, t, b, c, d) {
		return -c * ((t=t/d-1)*t*t*t - 1) + b;
	},
	easeInOutQuart: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
		return -c/2 * ((t-=2)*t*t*t - 2) + b;
	},
	easeInQuint: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t*t + b;
	},
	easeOutQuint: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t*t*t + 1) + b;
	},
	easeInOutQuint: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
		return c/2*((t-=2)*t*t*t*t + 2) + b;
	},
	easeInSine: function (x, t, b, c, d) {
		return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
	},
	easeOutSine: function (x, t, b, c, d) {
		return c * Math.sin(t/d * (Math.PI/2)) + b;
	},
	easeInOutSine: function (x, t, b, c, d) {
		return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
	},
	easeInExpo: function (x, t, b, c, d) {
		return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
	},
	easeOutExpo: function (x, t, b, c, d) {
		return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
	},
	easeInOutExpo: function (x, t, b, c, d) {
		if (t==0) return b;
		if (t==d) return b+c;
		if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
		return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
	},
	easeInCirc: function (x, t, b, c, d) {
		return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
	},
	easeOutCirc: function (x, t, b, c, d) {
		return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
	},
	easeInOutCirc: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
		return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
	},
	easeInElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
	},
	easeOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
	},
	easeInOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) p=d*(.3*1.5);
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
		return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
	},
	easeInBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*(t/=d)*t*((s+1)*t - s) + b;
	},
	easeOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
	},
	easeInOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) 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;
	},
	easeInBounce: function (x, t, b, c, d) {
		return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b;
	},
	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;
		}
	},
	easeInOutBounce: function (x, t, b, c, d) {
		if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b;
		return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;
	}
});

(function($) {
 
  $.fn.tweet = function(o){
    var s = {
      username: ["seaofclouds"],              // [string]   required, unless you want to display our tweets. :) it can be an array, just do ["username1","username2","etc"]
      list: null,                              //[string]   optional name of list belonging to username
      avatar_size: null,                      // [integer]  height and width of avatar if displayed (48px max)
      count: 3,                               // [integer]  how many tweets to display?
      intro_text: null,                       // [string]   do you want text BEFORE your your tweets?
      outro_text: null,                       // [string]   do you want text AFTER your tweets?
      join_text:  null,                       // [string]   optional text in between date and tweet, try setting to "auto"
      auto_join_text_default: "i said,",      // [string]   auto text for non verb: "i said" bullocks
      auto_join_text_ed: "i",                 // [string]   auto text for past tense: "i" surfed
      auto_join_text_ing: "i am",             // [string]   auto tense for present tense: "i was" surfing
      auto_join_text_reply: "i replied to",   // [string]   auto tense for replies: "i replied to" @someone "with"
      auto_join_text_url: "i was looking at", // [string]   auto tense for urls: "i was looking at" http:...
      loading_text: null,                     // [string]   optional loading text, displayed while tweets load
      query: null                             // [string]   optional search query
    };
    
    if(o) $.extend(s, o);
    
    $.fn.extend({
      linkUrl: function() {
        var returning = [];
        var regexp = /((ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/gi;
        this.each(function() {
          returning.push(this.replace(regexp,"<a href=\"$1\">$1</a>"));
        });
        return $(returning);
      },
      linkUser: function() {
        var returning = [];
        var regexp = /[\@]+([A-Za-z0-9-_]+)/gi;
        this.each(function() {
          returning.push(this.replace(regexp,"<a href=\"http://twitter.com/$1\">@$1</a>"));
        });
        return $(returning);
      },
      linkHash: function() {
        var returning = [];
        var regexp = / [\#]+([A-Za-z0-9-_]+)/gi;
        this.each(function() {
          returning.push(this.replace(regexp, ' <a href="http://search.twitter.com/search?q=&tag=$1&lang=all&from='+s.username.join("%2BOR%2B")+'">#$1</a>'));
        });
        return $(returning);
      },
      capAwesome: function() {
        var returning = [];
        this.each(function() {
          returning.push(this.replace(/\b(awesome)\b/gi, '<span class="awesome">$1</span>'));
        });
        return $(returning);
      },
      capEpic: function() {
        var returning = [];
        this.each(function() {
          returning.push(this.replace(/\b(epic)\b/gi, '<span class="epic">$1</span>'));
        });
        return $(returning);
      },
      makeHeart: function() {
        var returning = [];
        this.each(function() {
          returning.push(this.replace(/(&lt;)+[3]/gi, "<tt class='heart'>&#x2665;</tt>"));
        });
        return $(returning);
      }
    });

    function parse_date(date_str) {
      // The non-search twitter APIs return inconsistently-formatted dates, which Date.parse
      // cannot handle in IE. We therefore perform the following transformation:
      // "Wed Apr 29 08:53:31 +0000 2009" => "Wed, Apr 29 2009 08:53:31 +0000"
      return Date.parse(date_str.replace(/^([a-z]{3})( [a-z]{3} \d\d?)(.*)( \d{4})$/i, '$1,$2$4$3'));
    }

    function relative_time(time_value) {
      var parsed_date = parse_date(time_value);
      var relative_to = (arguments.length > 1) ? arguments[1] : new Date();
      var delta = parseInt((relative_to.getTime() - parsed_date) / 1000);
      var pluralize = function (singular, n) {
        return '' + n + ' ' + singular + (n == 1 ? '' : 's');
      };
      if(delta < 60) {
      return 'less than a minute ago';
      } else if(delta < (60*60)) {
      return 'about ' + pluralize("minute", parseInt(delta / 60)) + ' ago';
      } else if(delta < (24*60*60)) {
      return 'about ' + pluralize("hour", parseInt(delta / 3600)) + ' ago';
      } else {
      return 'about ' + pluralize("day", parseInt(delta / 86400)) + ' ago';
      }
    }

    function build_url() {
      var proto = ('https:' == document.location.protocol ? 'https:' : 'http:');
      if (s.list) {
        return proto+"//api.twitter.com/1/"+s.username[0]+"/lists/"+s.list+"/statuses.json?per_page="+s.count+"&callback=?";
      } else if (s.query == null && s.username.length == 1) {
        return proto+'//api.twitter.com/1/statuses/user_timeline.json?screen_name='+s.username[0]+'&count='+s.count+'&callback=?';
      } else {
        var query = (s.query || 'from:'+s.username.join(' OR from:'));
        return proto+'//search.twitter.com/search.json?&q='+escape(query)+'&rpp='+s.count+'&callback=?';
      }
    }

    return this.each(function(i, widget){
      var list = $('<ul class="tweet_list">').appendTo(widget);
      var intro = '<p class="tweet_intro">'+s.intro_text+'</p>';
      var outro = '<p class="tweet_outro">'+s.outro_text+'</p>';
      var loading = $('<p class="loading">'+s.loading_text+'</p>');

      if(typeof(s.username) == "string"){
        s.username = [s.username];
      }

      if (s.loading_text) $(widget).append(loading);
      $.getJSON(build_url(), function(data){
        if (s.loading_text) loading.remove();
        if (s.intro_text) list.before(intro);
        var tweets = (data.results || data);
        $.each(tweets, function(i,item){
          // auto join text based on verb tense and content
          if (s.join_text == "auto") {
            if (item.text.match(/^(@([A-Za-z0-9-_]+)) .*/i)) {
              var join_text = s.auto_join_text_reply;
            } else if (item.text.match(/(^\w+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+) .*/i)) {
              var join_text = s.auto_join_text_url;
            } else if (item.text.match(/^((\w+ed)|just) .*/im)) {
              var join_text = s.auto_join_text_ed;
            } else if (item.text.match(/^(\w*ing) .*/i)) {
              var join_text = s.auto_join_text_ing;
            } else {
              var join_text = s.auto_join_text_default;
            }
          } else {
            var join_text = s.join_text;
          };

          var from_user = item.from_user || item.user.screen_name;
          var profile_image_url = item.profile_image_url || item.user.profile_image_url;
          var join_template = '<span class="tweet_join"> '+join_text+' </span>';
          var join = ((s.join_text) ? join_template : ' ');
          var avatar_template = '<a class="tweet_avatar" href="http://twitter.com/'+from_user+'"><img src="'+profile_image_url+'" height="'+s.avatar_size+'" width="'+s.avatar_size+'" alt="'+from_user+'\'s avatar" title="'+from_user+'\'s avatar" border="0"/></a>';
          var avatar = (s.avatar_size ? avatar_template : '');
          var date = '<span class="tweet_time"><a href="http://twitter.com/'+from_user+'/statuses/'+item.id+'" title="view tweet on twitter">'+relative_time(item.created_at)+'</a></span>';
          var text = '<span class="tweet_text">' +$([item.text]).linkUrl().linkUser().linkHash().makeHeart().capAwesome().capEpic()[0]+ '</span>';

          // until we create a template option, arrange the items below to alter a tweet's display.
          list.append('<li>' + avatar + date + join + text + '</li>');

          list.children('li:first').addClass('tweet_first');
          list.children('li:odd').addClass('tweet_even');
          list.children('li:even').addClass('tweet_odd');
        });
        if (s.outro_text) list.after(outro);
        $(widget).trigger("loaded").trigger((tweets.length == 0 ? "empty" : "full"));
      });

    });
  };
})(jQuery);


function showResponse(responseText, statusText, xhr, $form) {
	//if(responseText['result'] == '0') {
		alert(statusText);
	//}
}

function convertString(str) {
	var str = str.replace(/\s+/g, '-').toLowerCase();
	return str;
}

/*function launchSlideshow() {
	$('#global-banner').css({"background":"none"});
	$('#media').cycle({
		fx: 'fade',
		timeout: 8000,
		speedIn: 800,  // speed of the 'in' transition 
		speedOut: 300,
		pause: true,
		before: function(curr, next, opts)
		{
			$('.caption').css({'top':'-420px','opacity':'0'});
		},
		after: function(curr, next, opts)
		{
			var count = opts.currSlide+1;
			if (count === count)
			{
				var alt = $(this).get(0).innerHTML;
				var altName = $(alt).attr('alt');
				var name = convertString(altName);
				
				var link = $(this).get(0).href;
			
				$('.caption').animate(
				{
					top: '0px',
					opacity: 1
				},
				{
					queue: false,
					duration: 400,
					easing: 'easeInBounce'
				});
				
				$('.caption').html('<a href="' + link + '"><img src="/img/home/' + name + '-foreground.png" alt="' + name + '"></a>');
			}
		}
	});
}*/

function checkEmail(email) 
{ 
    var pattern = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    var emailVal = $("#" + email).val();
    return pattern.test(emailVal);
}

$.metadata.setType("attr", "validate");

$(document).ready(function() {

	/*var src = "/img/home/";
	var url = "/portfolio/";
	
	$.ajax({
		type: "GET",
		url: "data/home.xml",
		dataType: "xml",
		success: function(xml) {
			var nodeLevel = 0;
			var img = $('client', xml); 
			$(xml).find('client').each(function() {
				if (nodeLevel > (img.length - 1)) {
					nodeLevel = 0;
				}
				var name = $(img.get(nodeLevel)).find('name').text();
				var image = name.replace(/\s+/g, '-').toLowerCase();
				var html = "";
				html += '<a href="'+url+image+'"><img src="'+src+image+'-background.jpg" alt="'+name+'" title="'+name+'"></a>';
				//$('#media').css('background','' + src+image + '-background.jpg');
				$('#media').append(html);
				nodeLevel++;
			});
			
		},
		complete: function(){
			$("#media").find('img').batchImageLoad({
				loadingCompleteCallback: launchSlideshow
			});
		}
	});*/
		
						   
	//tweets					   
	$("#tweets").tweet({
		username: "studiomoso",
		count: 3,
		loading_text: "loading tweets..."
	});	
	
	/*var email = $('#EmailSubscribe').val();
	
	var options = {
		type: "POST",
		url: "/forms/signup.php",
		data: "email=" + email,
		success: function(html)
		{
			$('#subscribe').hide();
			$('.success').css('padding','0px 0px 10px 0px').html(html);
		},
		resetForm: true
	};
	
	$("#subscribe").validate({
		submitHandler: function(form) {
			$(form).ajaxSubmit(options);
		},
		errorPlacement: function(error, element) {
			error.appendTo( element.parent().parent().parent() );
		},
		rules: {
			EmailSubscribe: {
				required: true,
				email: true
			}
		},
		messages: {
			EmailSubscribe: "Please enter a valid email address."
		}
	});	*/

	$('#subForm').validate(
	{
		submitHandler: function()
		{
			return false;
		},
		errorPlacement: function(error, element) 
		{
			error.appendTo( element.parent().parent().parent() );
		},
		rules: 
		{
			'cm-akkhl-akkhl':
			{
				required: true,
				email: true
			}
		},
		messages:
		{
			'cm-akkhl-akkhl': "Please enter a valid email address."
		}
	});
	
	$('#subForm button:submit').click(function()
	{
		$('#subForm').validate(
		{
			submitHandler: function()
			{
				return false;
			},
			errorPlacement: function(error, element) 
			{
				error.appendTo( element.parent().parent().parent() );
			},
			rules: 
			{
				'cm-akkhl-akkhl':
				{
					required: true,
					email: true
				}
			},
			messages:
			{
				'cm-akkhl-akkhl': "Please enter a valid email address."
			}
		});

		var formAction = $("form#subForm").attr("action");
				
		var id = "akkhl";
      	var emailId = id + "-" + id;
      	
      	/*if (!checkEmail(emailId)) 
      	{
      		
        	//$('.error').html('Please enter a valid email address');
       	 	return;
      	}*/
      	
      	var str = $("form#subForm").serialize();
      	//<![CDATA[
      	var serialized = str + "&action=" + formAction;
      	// ]]>

      	$.ajax(
      	{
      		type: "POST",
			url: "/forms/proxy.php",
			data: serialized,
			success: function(data)
			{
				if (data.search(/invalid/i) != -1) 
				{
					//$('.success').css('padding','0px 0px 10px 0px').html('The email address you supplied is invalid and needs to be fixed before you can subscribe to this list.');
				}
				else
				{
					$('#subForm').hide();
					$('.success').css('padding','0px 0px 10px 0px').html('Success!');
				}
			}
      	});
      	
      	/*var options = {
			type: "POST",
			url: "/forms/proxy.php",
			data: serialized,
			success: function(data)
			{
				console.log(data);
				if (data.search(/invalid/i) != -1) 
				{
					$('.success').css('padding','0px 0px 10px 0px').html('The email address you supplied is invalid and needs to be fixed before you can subscribe to this list.');
				}
				else
				{
					$('#subForm').hide();
					$('.success').css('padding','0px 0px 10px 0px').html('Success!');
				}
			},
			resetForm: true
		};
      	
      	$("#subForm").validate(
      	{
			submitHandler: function(form) 
			{
				$(form).ajaxForm(options);
			},
			errorPlacement: function(error, element) 
			{
				error.appendTo( element.parent().parent().parent() );
			},
			rules: 
			{
				EmailSubscribe: {
					required: true,
					email: true
				}
			},
			messages: 
			{
				EmailSubscribe: "Please enter a valid email address."
			}
		});*/
	});
	
	
});
//Cufon.replace('.column h2', { fontFamily: 'Ornito' });


/*
	Homepage slideshow
	Written & Maintained by Holmesy
*/
var active = false;
var bgSpeed = 900;
var txtSpeed = 300;
var currentState = 1;
var rotateSpeed = 8000;
var easeType = 'easeInOutSine';

$(function()
{
	$.ajax(
	{
		type: "GET",
		url: "/data/home.xml",
		dataType: "xml",
		success: function(xml) 
		{
			var img = $('client', xml); 
			var nodeLevel = Math.floor(img.length == 0);

			if (nodeLevel > 0 && nodeLevel < img.length ) 
			{
				var lastNode = nodeLevel - 1;
			} 
			else 
			{
				var name = $(img.get(nodeLevel)).find('name').text();
				var image = name.replace(/\s+/g, '-').toLowerCase();
				$('#title').css({'top':'-420px'});
				$('#title').animate({ top: '-420px' }, txtSpeed, easeType, function()
				{
					$('#title').html('<a href="/category/' + image + '"><img src="/img/home/' + image + '-foreground.png" alt="" /></a>');
				});
				$('#title').animate({ top: '0' }, txtSpeed, easeType);
				var lastNode = 0;
			}
			
			autoPlay(true);

			$(xml).find('client').each(function()
			{
				lastNode = nodeLevel;
				var name = $(img.get(nodeLevel)).find('name').text();
				var image = name.replace(/\s+/g, '-').toLowerCase();

				$('#odd').html('<a href="/category/' + image + '"><img src="/img/home/' + image + '-background.jpg" alt="" /></a>');
			});
			
			function animate(level)
			{
				if (currentState == 1) 
				{
					currentState = 0;
					offScreen = $('#even');
					onScreen = $('#odd');
				}
				else if (currentState == 0)
				{
					currentState = 1;
					offScreen = $('#odd');
					onScreen = $('#even');
				}
				
				if (level === true)
				{
					if (nodeLevel === 0)
					{
						nodeLevel = count;
					}
					else
					{
						nodeLevel = nodeLevel - 1;
					}
				}
				else
				{
					nodeLevel = nodeLevel + 1;
				}
				
				if (nodeLevel > (img.length - 1)) 
				{
					nodeLevel = 0;
				}
				
				var name = $(img.get(nodeLevel)).find('name').text();
				var image = name.replace(/\s+/g, '-').toLowerCase();
				
				offScreen.css({'opacity' : '0'});
				$('#title').css({'top':'-420px'});
				
				$(offScreen).html('<a href="/category/' + image + '"><img src="/img/home/' + image + '-background.jpg" alt="" /></a>');

				$('#title').animate({ top: '-420px'}, txtSpeed, easeType, function()
				{
					$('#title').html('<a href="/category/' + image + '"><img src="/img/home/' + image + '-foreground.png" alt="" /></a>');
				});
				$('#title').animate({ top: '0' }, txtSpeed, easeType);
			
				onScreen.animate({ opacity: 0 }, bgSpeed, easeType);
				offScreen.animate({ opacity: 1 }, bgSpeed, easeType, function() 
				{
				});
			}


			function autoPlay(active) 
			{
				if(active == true) 
				{
					auto = setInterval(function()
					{
						animate()
					}, rotateSpeed);
				} 
				else 
				{
					clearInterval(auto);
				}
			}
		}
	});
});




