(function($)
{
	var clock; 
		
	var methods = 
	{
    	init : function(options) 
    	{   
			return this.each(function(){     	
    			clock = $(this);
    			units = "<span id=\"days\" class=\"unit\"></span><span id=\"hours\" class=\"unit\"></span><span id=\"minutes\" class=\"unit\"></span><span id=\"seconds\" class=\"unit\"></span>";
    		
    			settings = 
    			{
    				'loop':'true',
    				'show':['Days', 'Hours', 'Minutes', 'Seconds'],
    				'date':'16/06/2012',
    				'titel':'Countdown',
    				'content':'lorem ipsum etc'    			
    			}
    			$.extend(settings,options);
    		
    			clock.prepend("<h3>"+settings['title']+"</h3>"); 
    			clock.append(units);
    			clock.append("<br/><br/><p>"+settings['text']+"</p>");
    			
				if(settings['loop'] == 'true') { setInterval(methods.calcdiff,1000); }
			});
   		},
 
   		calcdiff : function()
   		{
   			tempdate = settings['date'].split("/");
    		fdate = new Date(tempdate[2],(tempdate[1]-1),tempdate[0]); 
    		tdate = new Date(); 
   			
   			tempdiff = fdate.getTime()/1000 - tdate.getTime()/1000;
   			
   			diffin = {}
   			
   			diffin.days = Math.floor(tempdiff/86400);
   			if(diffin.days>0){ tempdiff = Math.floor(tempdiff%86400); }
   			
   			diffin.hours = Math.floor(tempdiff/3600);
   			if(diffin.hours>=0) { tempdiff = Math.floor(tempdiff%3600); }
   				
   			diffin.minutes = Math.floor(tempdiff/60);
   			if(diffin.minutes>=0) { tempdiff = Math.floor(tempdiff%60); }
   			
   			diffin.seconds = tempdiff;
   			methods.update(diffin);
   		},
   		
   		update : function(object)
   		{
   			clock.children("span#days").html(object['days'] + "<span class='label'>dagen</span>");
   			clock.children("span#hours").html(object['hours'] + "<span class='label'>uren</span>");
   			clock.children("span#minutes").html(object['minutes'] + "<span class='label'>minuten</span>");
   			clock.children("span#seconds").html(object['seconds'] + "<span class='label'>seconden</span>");
   		},
   		
   		test : function(string)
   		{
   			console.log(string);
   		}
   	};
 	 
 	$.fn.countdown = function(method) 
 	{
    	if (methods[method]) 
    	{
			return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
		} 
		else if (typeof method === 'object' || ! method) 
		{
			return methods.init.apply(this, arguments);
		} 
		else 
		{
			$.error('Method ' +  method + ' does not exist on jQuery.litebox');
    	}    
  	};

})(jQuery);
