function regError(msg)
{
  alert(msg);
}

function loadPage(page) {
  var oRPC = new jsRPC();
  oRPC.href = page + ((page.indexOf('?') != -1)?'&':'?') + 'html_load=1';
  oRPC.execute();
}

$.fn.pause = function(duration) {
  $(this).animate({ dummy: 1 }, duration);
  return this;
};
     
$(window).load(function () {
});
      
$(document).ready(function() {

});

var rotateCounter = 0;

function rotateHPImages(c)
{
  if (typeof(c) == 'undefined') c = (++rotateCounter);
  if (c != rotateCounter) return;
  rotateCounter++;

  var img = $('#hp-slider img:first');
  if (img.length > 0)
  {
    if (img.is(':visible'))
    {
      $('#hp-slider img:first').next().fadeIn(1000);
      $('#hp-slider img:first').fadeOut(1000, function() { 
        $(this).insertAfter($('#hp-slider img:last'));
      });
    }
    else
      img.fadeIn(1000);
    var s = '' + (c + 1);
    $('#hp-slider-timer').stop(true, true)
                         .animate({ width: '0' }, 200)
                         .animate({ width: '750px' }, 5000, function () {
      setTimeout('rotateHPImages(' + s + ')', 0);
    }); 
  }
} 

var rotateGalleryPointers = null; 
var rotateGalleryPointer = 0;
var rotateGalleryTimeout = 0;

function rotateGalleryImages(init)
{
  if (init)
  {
    rotateGalleryPointers = $('#gallery-links a');
    rotateGalleryPointer = 0;
    rotateGalleryTimeout = Math.random();
  }
  else
    rotateGalleryPointer = (rotateGalleryPointer + 1) % rotateGalleryPointers.length;
  
  $(rotateGalleryPointers[rotateGalleryPointer]).click();

  var s = '' + rotateGalleryTimeout;
  $('#hp-slider-timer').stop(true, true)
                       .animate({ width: '0' }, 200)
                       .animate({ width: '550px' }, 5000, function () {
    if (s == '' + rotateGalleryTimeout)
      setTimeout('rotateGalleryImages()', 0);
  }); 
}

function setLeftColumn(leftWidth, callback)
{
	$(document).ready(function () {
  called = false; 
	$('.inside').animate({ opacity: 0 }, 300, 'linear', function () {
	  if (called) return;
	  called = true;
		$('#content-left').width(leftWidth);
    $('#content-right').width(920 - leftWidth);
    h = Math.max($('#content-left').height(), $('#content-right').height());
	  $('#left-panel>div').html('');
	  $('#right-panel').width(0);
	  $('#left-panel').animate({ width: leftWidth + 'px', height: h + 'px'}, 300, 'easeOutQuad', function () {
	    $('#left-panel>div').html($('#content-left').html()); 
	    $('#right-panel').width(920 - $('#left-panel').width());
	    $('#right-panel>div').html($('#content-right').html()); 
	    $('.inside').css({ opacity: 0 }).show().animate({ opacity: 1 }, 300);
			$('#right-panel [html-load]').removeAttr('html-load');
      $('#left-panel [html-load]').removeAttr('html-load');
			updateLinks();
			
		  $('a[href^="http://youtu.be/"]').each(function() {
		    $(this).click(function () {
		      arr = this.href.split('/');
					if (arr.length < 4) return false;
		      watchVideo(arr[3]);
		      return cancelLink(); 
		    });
		  });
			
			if (typeof(callback) != 'undefined')
			  callback();
	  });

		t_h1 = $('#page h1[id!="page-title"]')[0];
		
		$('#page-title').animate({ opacity: 0 }, 300, function() {
	    if (typeof(t_h1) != 'undefined')
			{ 
	  	  $(this).html(t_h1.innerHTML);
        $('#h1').animate({ height: '53px' }, 200);
			}
	    else {
	  	  $(this).html('')
				$('#h1').animate({ height: 0 }, 200);
	    }		  
			$(this).animate({ opacity: 1 }, 300);
		});

	});	
	});
}

function watchVideo(code)
{
	$('#div-video-container').html('<iframe width="425" height="349" src="http://www.youtube.com/embed/' + code + '?hl=en&fs=1&autoplay=1" frameborder="0" allowfullscreen></iframe>');
	showModal($('#div-video')[0]);
}

function watchVideoInline(code)
{
  $('#div-video-container-inline').html('<iframe width="425" height="349" src="http://www.youtube.com/embed/' + code + '?hl=en&fs=1&autoplay=1" frameborder="0" allowfullscreen></iframe>');
}
