var mousecoords = null;
var current = '';
var locked = false;
var campaign_lock = false;
var campaign_cursor = 1;
var headlineText1 = '';
var headlineText2 = '';
var menu_hold = '';
var defaultsec = "";
var numClients = 1;

var ExternalFile = DUI.Class.create({
	init: function(filename, type) {
		this.filename = filename;
		if(type == null || type == "") {
			if(filename.indexOf('css') != -1)
				this.type = "css";
			else
				this.type="js";
		} else
			this.type = type;
		this.load();
	},
	load: function() {
		if(this.type == "css") {
			var fileref = document.createElement("link");
			fileref.setAttribute("rel", "stylesheet");
			fileref.setAttribute("type", "text/css");
			fileref.setAttribute("href", this.filename);
		} else {
			var fileref = document.createElement("script");
			fileref.setAttribute("type", "text/javascript");
			fileref.setAttribute("src", this.filename);
		}
		if (typeof fileref!="undefined")
			document.getElementsByTagName("head")[0].appendChild(fileref)
	}
});
var FileLoader = DUI.Class.create({
	init: function() {
		this.files = [];
	},
	load: function(filename) {
		if(!this.find(filename))
			this.files.push(new ExternalFile(filename));
	},
	find: function(filename) {
		for(var i=0; i<this.files.length; i++)
			if(this.files[i].filename == filename)
				return true;
		return false;
	}
});

var fileloader = new FileLoader();

var Loader = DUI.Class.create({
	init: function() {
		this.queue = [];
		this.loading = false;
	},
	add: function(name) {
		if(this.queue.length == 0)
			this.show();
		this.queue = [];
		this.queue.push(name);
	},
	remove: function(name) {
		if(this.queue.length == 0) return;
		for(var i=0; i<this.queue.length; i++)
			if(this.queue[i] == name)
				this.queue.splice(i, 1);
		if(this.queue.length == 0)
			this.hide();
	},
	show: function() {
		$("#loader").stop().css({ display : 'block' }).animate({ opacity : 1 }, { queue : false,  duration : 500 });
	},
	hide: function() {
		$("#loader").stop().animate({ opacity : 0 }, { queue : false,  duration : 500, complete : function() { $(this).css({ display : 'none' }); } });
	}
});
var loader = new Loader();

$(document).ready(function() {
  jQuery.queue.def = false;
  jQuery.easing.def = "easeOutQuad";
  $('body').css({ position : 'static' }).css({ position : 'relative' });

  $.scrollTo('0', 500);

  headlineText1 = $('#header h1').html();
  headlineText2 = $('#header h2').html();
  if($.browser.msie) {
    $('#header h1').html("");
    $('#header h2').html("");
  }
  
  setInterval(checkURL, 500);
  if(current != window.location.hash.substring(window.location.hash.lastIndexOf('#') + 1)) {
    if($.browser.msie)
      $('#body .campaign_wrapper').css({ opacity : 0 });
    $('#body').css({ opacity : 0 });
    $('#header').css({height : '110px'});
  }

  // Disable dotted focus on click
  $('a').live('click', function() {this.blur();});


  // Main menu hover
  $('#menu a').hover(menuHoverOn, menuHoverOff);
  function menuHoverOn(){
    $(this).find('img.on').stop()
	  .css({ opacity : 0, display : 'inline' })
	  .animate({ opacity : 1 } , { duration : 250 });
	$(this).find('img.caption').stop()
	  .css({ opacity : 0, display : 'inline', marginLeft : -10 })
	  .animate({ opacity : 1, marginLeft : 0 }, { duration : 250 });
  }
  function menuHoverOff(){
    $(this).find('img.on').stop()
      .animate({ opacity : 0 } , { duration : 250, complete:function(){ $(this).css({ display: 'none' }); } });
    $(this).find('img.caption').stop()
      .animate({ opacity : 0, marginLeft : -10 }, { duration : 250, complete:function(){ $(this).css({ display: 'none' }); } });
  }

  // Footer social hover
  $('#social a').hover(socialOn, socialOff);
  function socialOn(){
    $(this).find('img.on').stop()
	  .css({ opacity : 0, display: 'block' })
	  .animate({ opacity : 1 } , { duration : 200 });
  }
  function socialOff(){
    $(this).find('img.on').stop()
	  .animate({ opacity : 0 } , { duration : 300, complete:function(){ $(this).css({ display: 'none' }); } });
  }

  // Homepage Campaign
  $('.campaign .left_arrow').live('click', function() {
    if(!campaign_lock) {
          campaign_lock = true;
          setTimeout('campaign_lock = false;',1000);
	  moveCampaignLeft();
    }
  });
  $('.campaign .right_arrow').live('click', function() {
    if(!campaign_lock) {
          campaign_lock = true;
          setTimeout('campaign_lock = false;',1000);
	  moveCampaignRight();
    }
  })
  
  // Handle navigation AJAX clicks
  $('a').live('click', function(e) {
    //if((this.href.indexOf('http://') == -1 || this.href.indexOf('http://www.noblestudios.com/') != -1) && this.href.indexOf('mailto:') == -1 && this.href.indexOf('javascript:') == -1 && this.target != '_blank') {
    if(this.href.indexOf('mailto:') == -1 && this.href.indexOf('javascript:') == -1 && this.target != '_blank' && e.button == 0 && !$(this).hasClass('popup')) {
      $.scrollTo('0', 500);
      $(this).css({color:$(this).css('color')});
      // Generate hash from link href.  Get URL
      var theHash = this.href.replace('http://www.noblestudios.com/','');
      getURL(theHash, this);
      return false;
    }
  });

});


// AJAX page request getURL(url#hash)
String.prototype.capitalize = function(){ //v1.0
    return this.replace(/\w+/g, function(a){
        if(a == "and" || a == "of") return a;
        return a.charAt(0).toUpperCase() + a.substr(1).toLowerCase();
    });
};


function convertHash(hash) {
  hash = hash.replace(new RegExp( "_", "g" ), " ");
  if(hash.lastIndexOf("/") == hash.length - 1)
    hash = hash.substring(0, hash.lastIndexOf("/"));
  return hash.replace(new RegExp( "/", "g" ), " > ").capitalize();
}

function getURL(hash, linkObj) {
	hash = hash.substring(hash.lastIndexOf('#') + 1);
	if(!locked && current!=hash ) {
		loader.add("page");
		locked = true;
                pageTracker._trackPageview("/"+hash+".html" );
		var hash_ref = hash.split("/");
		if( hash_ref[0] != 'about' && hash_ref[0] != 'showcase' && hash_ref[0] != 'clients' && hash_ref[0] != 'news' && hash_ref[0] != 'contact' && hash_ref[0] != 'videos')
			hash='';

		//animate content out
		if($.browser.msie) {
		    $('body').css({ position : 'static' }).css({ position : 'relative' });
		    $('#body, #body #showcase, #body div#projects, #body div#showcase_pagination .buttons, #body .clientswrapper, #body .campaign_wrapper, #body #news_wrapper .pagination, #body #map_wrapper').animate({ opacity : 0 }, { duration : 200, queue : false });
		} else
		    $('#body').animate({ opacity : 0 }, { duration : 200, queue : false });

		$('#hidden').load('http://www.noblestudios.com/' + hash + '/content/ajax/', function (responseText, textStatus, XMLHttpRequest) {
			loader.remove("page");
			if(responseText != '') {
				//update title
				if(document.title) document.title = convertHash('Noble Studios, Inc.'+((hash != "") ? ' > '+hash : ' - Marketing and Web Development'));  //$('#content .page_title:first').html();
				//call pngFix() for new content if needed

			  if(!$.browser.msie && (hash_ref[0] == "index" || hash_ref[0] == ""))
				headTextOn();
			  else
				headTextOff();
				//after fade content out is finished:
				setTimeout(function() {
					if ( hash == '' ) hash = 'index';
					current = hash;
					//update url
					window.location.hash = hash;
					//save hash for ie
					$('#hiddenFrame').attr('src', 'http://www.noblestudios.com/incl/store_hash?hash='+hash);
					//determine height of new content
					var h = $('#hidden').height();
					//animate in header
					//if( hash == 'index' && $.browser.msie) headTextOn();
					$('#header').animate({height : '110px'}, { duration : 250, queue : false });
					//animate in body
					$('#body .inner').animate({ height : (h > 121) ? h : 121 },{ duration : 500, complete : function(){$('#body .inner').css({height:'auto', overflow:'visible'});} });

					var tempname = current.split("/")[0];
					var temppath = "http://www.noblestudios.com/index.php/";
					switch(tempname) {
						case "index":
							break;
						default:
//							fileloader.load(temppath+tempname+"/css_"+tempname);
							break;
					}
					//after animate in
					setTimeout(function() {
						//move content from div#hidden to div.inner
						$('#body .inner').html($('#hidden').html());
						$('#hidden').html('');
						
						
						//call initialize functions after new content is loaded
						var current_ref = current.split("/")
						var path = "http://www.noblestudios.com/index.php/";

						if ( current_ref[0] == 'index' )
							initHome();
						else if ( current_ref[0] == 'about' ) {
							var aboutPath = path + 'about/';
							
							if(!fileloader.find(aboutPath+"js_about"))
								fileloader.load(aboutPath+"js_about");
							else
								initAbout();
						} else if ( current_ref[0] == 'showcase' ) {
							var showcasePath = path + 'showcase/';
							if(!fileloader.find(showcasePath+"js_showcase"))
								fileloader.load(showcasePath+"js_showcase");
							else
								initShowcase();
						} else if ( current_ref[0] == 'clients' ) {
							var clientsPath = path + 'clients/';
							if(!fileloader.find(clientsPath+"js_clients"))
								fileloader.load(clientsPath+"js_clients");
							else
								initClients();
						} else if ( current_ref[0] == 'news' ) {
							var newsPath = path + 'news/';
							if(!fileloader.find(newsPath+"js_news"))
								fileloader.load(newsPath+"js_news");
							else
								initNews();
						} else if ( current_ref[0] == 'contact' ) {
							var contactPath = path + 'contact/';
							if(!fileloader.find(contactPath+"js_contact"))
								fileloader.load(contactPath+"js_contact");
							else
								initContact();
						} else if (current_ref[0] == 'videos')
							$('#sub_wrapper h1').each( h1Replace );

						//$('#body').animate({ opacity : 1 }, { duration : 500, complete : function() { if(jQuery.browser.msie) this.style.removeAttribute("filter"); } });
						if($.browser.msie) {
						    $('body').css({ position : 'static' }).css({ position : 'relative' });
						    $('#body, #body #showcase, #body div#projects, #body div#showcase_pagination .buttons, #body .clientswrapper, #body #news_wrapper .pagination, #body #map_wrapper').animate({ opacity : 1 }, { duration : 200, queue : false, complete : function() { if(jQuery.browser.msie) this.style.removeAttribute("filter"); } });
						} else
						    $('#body').animate({ opacity : 1 }, { duration : 200, queue : false, complete : function() { if(jQuery.browser.msie) this.style.removeAttribute("filter"); } });
						$('#pagewrapper').css({'position':'static'}).css({'position':'relative'});
						$('body').css({'position':'static'}).css({'position':'relative'});
						locked = false;
						if (current_ref.length=2)
						  $(linkObj).mouseout();
					}, 500);
				}, 200);
			} else
				locked = false;
		});
	}
}

function checkURL() {
  if(!locked) {
    var hash_page = window.location.hash.substring(window.location.hash.lastIndexOf('#') + 1);
    if(document.frames && document.frames['hiddenFrame'] && current != document.frames['hiddenFrame'].getHash()) window.location.hash = document.frames['hiddenFrame'].getHash();
    if(current != hash_page ) getURL(hash_page);
  }
}

// flash text replace
function h1Replace(index, element){
    $(this).css({
        width: $(this).width(),
        height:$(this).height()
      }).flash({
      swf: 'http://www.noblestudios.com//images/uploads/fonts/humanist777_light_replace.swf',
      flashvars: { text : encodeURIComponent($(this).html()),  color : '#ffffff',  width : $(this).width(),  height : $(this).height(), size : 35, align : 'left', line : 12,  spacing : -0.5 },
      height: $(this).height(), width: $(this).width(), bgcolor: '#080809', wmode: 'transparent'
      });
}

function h2Replace(index, element){
    $(this).css({
        width: $(this).width(),
        height:$(this).height()
      }).flash({
      swf: 'http://www.noblestudios.com//images/uploads/fonts/humanist777_light_replace.swf',
      flashvars: { text : encodeURIComponent($(this).html()),  color : '#939598',  width : $(this).width(),  height : $(this).height(), size : 20, align : 'left', line : 14,  spacing : 0 },
      height: $(this).height(), width: $(this).width(), bgcolor: '#080809', wmode: 'transparent'
      });
}

function h3Replace(index, element){
    $(this).css({
        width: $(this).width(),
        height:$(this).height()
      }).flash({
      swf: 'http://www.noblestudios.com//images/uploads/fonts/humanist777_light_replace.swf',
      flashvars: { text : encodeURIComponent($(this).html()),  color : '#ffffff',  width : $(this).width(),  height : $(this).height(), size : 28, align : 'left', line : 8,  spacing : -0.5 },
      height: $(this).height(), width: $(this).width(), bgcolor: '#080809', wmode: 'transparent'
      });
}

function headTextOn(){
   $('#header h1').html(headlineText1).flash({
      swf: 'http://www.noblestudios.com//images/uploads/fonts/humanist777_light_replace.swf',
      flashvars: { text : headlineText1,  color : '#ffffff',  width : 976,  height : 44, size : 35, align : 'center', line : 0,  spacing : -0.5 },
      height: 44, width: 976, bgcolor: '#080809', wmode: 'transparent'
      });
   $('#header h2').html(headlineText2).flash({
      swf: 'http://www.noblestudios.com//images/uploads/fonts/humanist777_light_replace.swf',
      flashvars: { text : headlineText2,  color : '#939598',  width : 976,  height : 120, size : 20, align : 'center', line : 14,  spacing : 0 },
      height: 120, width: 976, bgcolor: '#080809', wmode: 'transparent'
      });
}
function headTextOff(){
      $('#header h1').html('');
      $('#header h2').html('');
}

function sizeFlash() {
  var screenWidth = $(this).width();
  var screenHeight = $(this).height();
  $('#fourthWard').width( screenWidth );
  $('#fourthWard').height( screenHeight );
  $('#fourthWard object').width( screenWidth );
  $('#fourthWard object').height( screenHeight );
}

$(document).mousemove(function(e) {
	mousecoords = { x : e.pageX, y : e.pageY };
});

$(document).ready(function() {
	$('#blackout').css('opacity', 0).click(hideVideo);
	$('#lightbox').click(function(e){e.stopPropagation()});});
function showVideo(src) {
	$('#lightbox').animate({width:800,height: 600,marginTop:-310,marginLeft:-410},{queue:false,duration:500}).html('').flash({
		swf: 'http://www.noblestudios.com/images/uploads/template/swf/flv_player_big.swf',
		flashvars: { file : src },
		height: '100%', width: '100%', wmode: 'opaque'
	});//.append('<a href="javascript:void(0)" onclick="hideVideo()">Close</a>');
	$('#blackout').css('display','block').animate({opacity:1},{queue:false,duration:500});}
function hideVideo() {
	$('#lightbox').animate({width:0,height: 0,marginTop:-10,marginLeft:-10},{queue:false,duration:500});
	$('#blackout').animate({opacity:0},{queue:false,duration:250,complete:function() {
		$(this).css('display','none');
		$('#lightbox').html();
	}});
}

var flvImg = '';
var current_campaign = 1;
var campaignsDesc = new Array();
var campaignsSrc = new Array();
var campaignsLink = new Array();

campaignsDesc[1] = "You can follow us... wherever we may go.  There isn't an ocean too deep. A mountain so high it can keep. Keep us away. ";
campaignsSrc[1] = "http://noblestudios.com/images/uploads/campaign/2010_0112_CampaignImage_social.jpg";
campaignsLink[1] = "http://noblestudios.com/#news/page/social_noble";

campaignsDesc[2] = "Noble joins forces with Regen - powered by light.";
campaignsSrc[2] = "http://noblestudios.com/images/uploads/campaign/2010_0112_CampaignImage_regen.jpg";
campaignsLink[2] = "http://noblestudios.com/#news/page/regen_living";

campaignsDesc[3] = "";
campaignsSrc[3] = "http://noblestudios.com/images/uploads/campaign/20100129_CampaignImage_dave.jpg";
campaignsLink[3] = "http://www.noblestudios.com/#about/awards/";

campaignsDesc[4] = "Microsoft Photosynth - Noble Studios is working on a project using the new Microsoft Photosynth software released in 2009.";
campaignsSrc[4] = "http://noblestudios.com/images/uploads/campaign/synth.jpg";
campaignsLink[4] = "http://www.noblestudios.com/#contact/";

campaignsDesc[5] = "Congratulations Nevada Magazine Wins First Place in 2008 National Headliner Awards";
campaignsSrc[5] = "http://noblestudios.com/images/uploads/campaign/20090825_CampaignImage_nevm.jpg";
campaignsLink[5] = "http://www.noblestudios.com/#about/awards/";

campaignsDesc[6] = "Here's to happy memories in 2009!";
campaignsSrc[6] = "http://noblestudios.com/images/uploads/campaign/karma.jpg";
campaignsLink[6] = "javascript:addFlvPlayer('http://www.noblestudios.com/images/uploads/flv_player/video.flv')";

campaignsDesc[7] = "Congratulations Holland Project Wins in the 2008 Communicator Awards";
campaignsSrc[7] = "http://noblestudios.com/images/uploads/campaign/20090825_CampaignImage_holl.jpg";
campaignsLink[7] = "http://www.noblestudios.com/#about/awards/";

campaignsDesc[8] = "From our desk to Autodesk.";
campaignsSrc[8] = "http://noblestudios.com/images/uploads/campaign/fromourdesk.jpg";
campaignsLink[8] = "http://www.noblestudios.com/#showcase/";

campaignsDesc[9] = "Nice work Michelangelo! We'll see you soon at the 2009 Noble Retreat.";
campaignsSrc[9] = "http://noblestudios.com/images/uploads/campaign/europe.jpg";
campaignsLink[9] = "http://www.noblestudios.com/#news/page/we_made_our_goal2";

campaignsDesc[10] = "Autodesk Dragonfly is alive!";
campaignsSrc[10] = "http://noblestudios.com/images/uploads/campaign/dragonfly.jpg";
campaignsLink[10] = "http://www.noblestudios.com/#news/page/autodesk_project_dragonfly";

campaignsDesc[11] = "Happy Birthday Noble!";
campaignsSrc[11] = "http://noblestudios.com/images/uploads/campaign/bday.jpg";
campaignsLink[11] = "http://www.noblestudios.com/#about/";


function initHome(){
  if($('#header h1').css('display') == 'none') {
    $('#header h1').css('display', 'block');
    $('#header h2').css('display', 'block');
  }
  introAnimation();
  $('#home_wrapper h3').each( h3Replace );
}

var introTimeout = null;
function introAnimation() {
  $('*').stop( true );
  clearTimeout(introTimeout);
  $('#header').css({ height : 110});
  //$('#header .content').css({ opacity : 0, visibility : 'visible' });
  //$('#header-overlay').css({ opacity : 1, visibility : 'visible' });
  $('.module').css({ opacity : 0, visibility : 'visible', marginTop : 0 });
  $('.campaign').css({ opacity : 0, visibility : 'visible' });
if($.browser.msie)
  $('.campaign_wrapper').css({ opacity : 0, visibility : 'visible' });
  $('#header').animate({ height : 340 }, { duration : 1000, complete : function() { if($.browser.msie) headTextOn(); } });
  introTimeout = setTimeout(function() {
    //$('#header .content').animate({ opacity : 1 }, { duration : 1000 });
    //$('#header-overlay').animate({ opacity : 0 }, { duration : 1000 });
    $('.module:first').animate({ opacity : 1, marginTop : 20 }, { duration : 300, complete : animateModule });
    introTimeout = setTimeout(function() {
      $('.campaign').animate({ opacity : 1 }, { duration : 1000, complete : initCampaign });
if($.browser.msie)
  $('.campaign_wrapper').animate({ opacity : 1 }, { duration : 1000 });
      //$('#header-overlay').css({ visibility : 'hidden' });
    }, 1000);
  }, 700);
}

function animateModule() {
  $(this).find('+.module').animate({ opacity : 1, marginTop : 20 }, { duration : 300, complete : animateModule });
}

function initCampaign() {
  $('.campaign').css({opacity:'none'});
  //addFlvPlayer(null);
  current_campaign = 1;
  campaign_cursor = 1;
  flvImg = '';
}

function addFlvPlayer(flv) {
  switch(campaign_cursor) {
    case 1:
        $('.campaign_wrapper .campaign1').attr("id", "flv_1");
        break;
    case 2:
        $('.campaign_wrapper .campaign2').attr("id", "flv_1");
        break;
    case 3:
        $('.campaign_wrapper .campaign3').attr("id", "flv_1");
        break;
  }
  if($('.campaign_wrapper #flv_1').size() > 0) {
    if(flv == '' || flv == null) flv = 'http://www.noblestudios.com/images/uploads/flv_player/video.flv';
    flvImg = $('.campaign_wrapper #flv_1').html();
    $('.campaign_wrapper #flv_1').flash({swf:'http://www.noblestudios.com/images/uploads/flv_player/flv_player.swf', flashvars:{video:flv}, height:352, width:907, wmode: 'transparent' });	
  }
}

function removeFlvPlayer() {
  $('.campaign_wrapper #flv_1').html(flvImg);
  $('.campaign_wrapper #flv_1').attr("id", "");
  $flvImg = '';
}

function updatePagination(i) {
	$('.campaign .pagination span').removeClass('active');
	$('.campaign .pagination span:eq('+i+')').addClass('active');
}

function moveCampaignLeft(){
  switch(campaign_cursor) {
    case 1:
         $('.campaign_wrapper .campaign2').css('left','907px');
         $('.campaign_wrapper .campaign1').css('left','1814px').animate({left: '2721px'}, 1000);
         $('.campaign_wrapper .campaign3').css('left','907px').animate({left: '1814px'}, 1000);
         var next_campaign = current_campaign-2;
         if( next_campaign < 1 ) {
           next_campaign += campaignsSrc.length-1;
         }
         var desc = campaignsDesc[next_campaign];
         var src = campaignsSrc[next_campaign];
         var link = campaignsLink[next_campaign];
         var html = '';
         if(link != ''){
           html += '<a href="'+link+'" '+((link.indexOf("noblestudios.com") == -1) ? 'target="_blank"' : '')+'>';
         }
         html += '<img src="'+src+'" alt="'+desc+'" />';
         if(link != ''){
           html += '</a>';
         }
         $('.campaign_wrapper .campaign2').html(html);
         current_campaign--;
         if(current_campaign < 1) {
           current_campaign = campaignsSrc.length-1;
         }
		 updatePagination(current_campaign-1);
         campaign_cursor = 3;
         break;
   case 2:
         $('.campaign_wrapper .campaign3').css('left','907px');
         $('.campaign_wrapper .campaign2').css('left','1814px').animate({left: '2721px'}, 1000);
         $('.campaign_wrapper .campaign1').css('left','907px').animate({left: '1814px'}, 1000);
         var next_campaign = current_campaign-2;
         if( next_campaign < 1 ) {
           next_campaign += campaignsSrc.length-1;
         }
         var desc = campaignsDesc[next_campaign];
         var src = campaignsSrc[next_campaign];
         var link = campaignsLink[next_campaign];
         var html = '';
         if(link != ''){
           html += '<a href="'+link+'" '+((link.indexOf("noblestudios.com") == -1) ? 'target="_blank"' : '')+'>';
         }
         html += '<img src="'+src+'" alt="'+desc+'" />';
         if(link != ''){
           html += '</a>';
         }
         $('.campaign_wrapper .campaign3').html(html);
         current_campaign--;
         if(current_campaign < 1) {
           current_campaign = campaignsSrc.length-1;
         }
		 updatePagination(current_campaign-1);
         campaign_cursor = 1;
         break;
   case 3:
         $('.campaign_wrapper .campaign1').css('left','907px');
         $('.campaign_wrapper .campaign3').css('left','1814px').animate({left: '2721px'}, 1000);
         $('.campaign_wrapper .campaign2').css('left','907px').animate({left: '1814px'}, 1000);
         var next_campaign = current_campaign-2;
         if( next_campaign < 1 ) {
           next_campaign += campaignsSrc.length-1;
         }
         var desc = campaignsDesc[next_campaign];
         var src = campaignsSrc[next_campaign];
         var link = campaignsLink[next_campaign];
         var html = '';
         if(link != '') {
           html += '<a href="'+link+'" '+((link.indexOf("noblestudios.com") == -1) ? 'target="_blank"' : '')+'>';
         }
         html += '<img src="'+src+'" alt="'+desc+'" />';
         if(link != '') {
           html += '</a>';
         }
         $('.campaign_wrapper .campaign1').html(html);
         current_campaign--;
         if(current_campaign < 1) {
           current_campaign = campaignsSrc.length-1;
         }
		 updatePagination(current_campaign-1);
         campaign_cursor = 2;
         break;
  }
  if(flvImg != '') {removeFlvPlayer();}
}
function moveCampaignRight(){
  switch(campaign_cursor) {
    case 1:
         $('.campaign_wrapper .campaign3').css('left','2721px');
         $('.campaign_wrapper .campaign1').css('left','1814px').animate({left: '907px'}, 1000);
         $('.campaign_wrapper .campaign2').css('left','2721px').animate({left: '1814px'}, 1000);
         //Do move Left
         var next_campaign = current_campaign+2;
         if( next_campaign >= campaignsSrc.length ) {
           next_campaign -= campaignsSrc.length-1;
         }
         var desc = campaignsDesc[next_campaign];
         var src = campaignsSrc[next_campaign];
         var link = campaignsLink[next_campaign];
         var html = '';
         if(link != ''){
           html += '<a href="'+link+'" '+((link.indexOf("noblestudios.com") == -1) ? 'target="_blank"' : '')+'>';
         }
         html += '<img src="'+src+'" alt="'+desc+'" />';
         if(link != ''){
           html += '</a>';
         }
         $('.campaign_wrapper .campaign3').html(html);
         current_campaign++;
         if(current_campaign >= campaignsSrc.length) {
           current_campaign = 1;
         }
		 updatePagination(current_campaign-1);
         campaign_cursor = 2;
         break;
   case 2:
         $('.campaign_wrapper .campaign1').css('left','2721px');
         $('.campaign_wrapper .campaign2').css('left','1814px').animate({left: '907px'}, 1000);
         $('.campaign_wrapper .campaign3').css('left','2721px').animate({left: '1814px'}, 1000);
         //Do move Left
         //Move Header 1 to the right spot
         var next_campaign = current_campaign+2;
         if( next_campaign >= campaignsSrc.length ) {
           next_campaign -= campaignsSrc.length-1;
         }
         var desc = campaignsDesc[next_campaign];
         var src = campaignsSrc[next_campaign];
         var link = campaignsLink[next_campaign];
         var html = '';
         if(link != ''){
           html += '<a href="'+link+'" '+((link.indexOf("noblestudios.com") == -1) ? 'target="_blank"' : '')+'>';
         }
         html += '<img src="'+src+'" alt="'+desc+'" />';
         if(link != ''){
           html += '</a>';
         }
         $('.campaign_wrapper .campaign1').html(html);
         current_campaign++;
         if(current_campaign >= campaignsSrc.length) {
           current_campaign = 1;
         }
		 updatePagination(current_campaign-1);
         campaign_cursor = 3;
         break;
   case 3:
         $('.campaign_wrapper .campaign2').css('left','2721px');
         $('.campaign_wrapper .campaign3').css('left','1814px').animate({left: '907px'}, 1000);
         $('.campaign_wrapper .campaign1').css('left','2721px').animate({left: '1814px'}, 1000);
         //Do move Left
         var next_campaign = current_campaign+2;
         if( next_campaign >= campaignsSrc.length ) {
           next_campaign -= campaignsSrc.length-1;
         }
         var desc = campaignsDesc[next_campaign];
         var src = campaignsSrc[next_campaign];
         var link = campaignsLink[next_campaign];
         var html = '';
         if(link != ''){
           html += '<a href="'+link+'" '+((link.indexOf("noblestudios.com") == -1) ? 'target="_blank"' : '')+'>';
         }
         html += '<img src="'+src+'" alt="'+desc+'" />';
         if(link != ''){
           html += '</a>';
         }
         $('.campaign_wrapper .campaign2').html(html);
         current_campaign++;
         if(current_campaign >= campaignsSrc.length) {
           current_campaign = 1;
         }
		 updatePagination(current_campaign-1);
         campaign_cursor = 1;
         break;
  }
  if(flvImg != '') {removeFlvPlayer();}
}