$(document).ready( function() {
	ROLL.rollover.init();
	HOV.rollover.init();
	CNFRM.confirmit.init();
	$('a.lightbox').lightBox(); // Select all links with lightbox class
	$('a.lightbox-admin').lightBox(); // Select all links with lightbox class
	$('#slideshow').cycle({ 
	    fx: 'scrollRight' 
	});
	$('#contentmiddleb').hover(function() {
		$("#projects_menu").attr('class', 'inactive');
		$("#profiles_menu").attr('class', 'inactive');
		$("#press_menu").attr('class', 'inactive');
	});
});


function showPreview(coords)
{
	var rx = 100 / coords.w;
	var ry = 100 / coords.h;

	$('#preview').css({
		width: Math.round(rx * 500) + 'px',
		height: Math.round(ry * 370) + 'px',
		marginLeft: '-' + Math.round(rx * coords.x) + 'px',
		marginTop: '-' + Math.round(ry * coords.y) + 'px'
	});
};

function showCoords(c)
{
	$('#x').val(c.x);
	$('#y').val(c.y);
	$('#x2').val(c.x2);
	$('#y2').val(c.y2);
	$('#w').val(c.w);
	$('#h').val(c.h);
};


CNFRM = {};
CNFRM.confirmit = {
	init : function() {
		$(".confirm").click( function() {
			return confirm('Are you sure you want to delete this item? This cannot be undone.');
		});
	}
};



HOV = {};
HOV.rollover = {
	init : function() {
		$("#projects").hover( function() {
			$("#projects_menu").attr('class', 'active');
			$("#profiles_menu").attr('class', 'inactive');
			$("#press_menu").attr('class', 'inactive');
		});
		$("#profiles").hover( function() {
			$("#projects_menu").attr('class', 'inactive');
			$("#profiles_menu").attr('class', 'active');
			$("#press_menu").attr('class', 'inactive');
		});
		$("#press").hover( function() {
			$("#projects_menu").attr('class', 'inactive');
			$("#profiles_menu").attr('class', 'inactive');
			$("#press_menu").attr('class', 'active');
		});
	}
};

ROLL = {};

ROLL.rollover = 
{
   init: function()
   {
      this.preload();
      
      $(".ro").hover(
         function () { $(this).attr( 'src', ROLL.rollover.newimage($(this).attr('src')) ); }, 
         function () { $(this).attr( 'src', ROLL.rollover.oldimage($(this).attr('src')) ); }
      );
   },

   preload: function()
   {
      $(window).bind('load', function() {
         $('.ro').each( function( key, elm ) { $('<img>').attr( 'src', ROLL.rollover.newimage( $(this).attr('src') ) ); });
      });
   },
   
   newimage: function( src )
   { 
      return src.substring( 0, src.search(/(\.[a-z]+)$/) ) + '2' + src.match(/(\.[a-z]+)$/)[0]; 
   },

   oldimage: function( src )
   { 
      return src.replace(/2\./, '.'); 
   }
};