/*
 *	Focus-UI Library
 *
 *	Copyright (c) 2009 Focus Imaging Limited - http://www.focus-global.com
 */


focus_ui = {
	init: function(  ){
		
		focus_ui.day_night.init();
		
		jQuery('img.rollover')
			.bind('mouseover',function(event){ focus_ui.img.mouseover(this); })
			.bind('mouseout',function(event){ focus_ui.img.mouseout(this); });		
	},

	bookmarksite: function(){
		if (window.sidebar) // firefox
		{
			window.sidebar.addPanel(document.title, location.href, "");
		}
		else if(window.opera && window.print) // opera
		{
			var elem = document.createElement('a');
			elem.setAttribute('href',location.href);
			elem.setAttribute('title',document.title);
			elem.setAttribute('rel','sidebar');
			elem.click();
		} 
		else if(document.all) // ie
		{
			window.external.AddFavorite(location.href, document.title);
		}
	},
	
	clock: {
		current: null,
		init: function( current_time )
		{
			focus_ui.clock.current = new Date(current_time);
			setInterval("focus_ui.clock.refresh()", 1000);
		},
		padZero: function(what){
			return (what.toString().length==1) ? '0' + what : what;
		},
		refresh: function()
		{
			focus_ui.clock.current.setSeconds( focus_ui.clock.current.getSeconds()+1 );
			var s = focus_ui.clock.padZero(focus_ui.clock.current.getHours())+":"+ focus_ui.clock.padZero(focus_ui.clock.current.getMinutes())+":"+ focus_ui.clock.padZero(focus_ui.clock.current.getSeconds());
			jQuery('#focus_ui_clock').html( s );
		}
	},
	
	img: {
		mouseover: function( el ){
			var el = jQuery(el);
			el.attr('src', el.attr('src').replace('rollout', 'rollover') );
		},
		mouseout: function( el ){
			var el = jQuery(el);
			el.attr('src', el.attr('src').replace('rollover', 'rollout') );
		}
	},
	
	day_night: {
		init: function() {
			jQuery('div.day_night_img').each(function() {
				var img = jQuery(this).find('img.view');
				
				jQuery(this).find('img.change_btn')
					.bind('click', function() { focus_ui.day_night.changeView( img ) });
			});				
		},
		
		changeView: function( target ) {	
			if (target.attr('src').match('day')) {
				target.attr('src', target.attr('src').replace('day', 'night') );
			}
			else {
				target.attr('src', target.attr('src').replace('night', 'day') );
			}			
		}
	},
		
	scroller: {
		intval: null,
		init: function( selector, speed ){
			if( typeof(speed)=='underfind' )
			{
				speed = 50;
			}
			var parentBox = jQuery(selector);
			parentBox.find('.scroller-forward')
				.bind('mouseover',function(event){ focus_ui.scroller.next( selector, speed ); })
				.bind('mouseout',function(event){ focus_ui.scroller.stop(); });
			parentBox.find('.scroller-backward')
				.bind('mouseover',function(event){ focus_ui.scroller.prev( selector, speed ); })
				.bind('mouseout',function(event){ focus_ui.scroller.stop(); })
				.css('display', 'none');
		}, 
	
		move: function( mode, selector) {		
			var parentBox = jQuery(selector);
			var box = parentBox.find('.scroller-mainbody');
			var max = box.attr('scrollWidth') - box.width();
			
			if (mode == 'next') {
				if ( box.scrollLeft() == max ) {
					parentBox.find('.scroller-forward').css('display', 'none');
				}
				else {
					parentBox.find('.scroller-backward').css('display', '');
					box.scrollLeft(box.scrollLeft() + 1 );
				}										
			}
			else {
				if ( box.scrollLeft() == 0) {
					parentBox.find('.scroller-backward').css('display', 'none');
				}
				else {	
					parentBox.find('.scroller-forward').css('display', '');
					box.scrollLeft(box.scrollLeft() - 1 );										
				}
			}
		},
		
		next: function( selector, speed ){
			focus_ui.scroller.intval = setInterval("focus_ui.scroller.move('next', '"+ selector +"')", speed );
		},
		
		prev: function( selector, speed ){
			focus_ui.scroller.intval = setInterval("focus_ui.scroller.move('prev', '"+selector+"')", speed );
		},
		
		stop: function(){
			window.clearInterval(focus_ui.scroller.intval);
		}
	
	},
	
	vscroller: {
		intval: null,
		init: function( selector, speed ){
			if( typeof(speed)=='underfind' )
			{
				speed = 50;
			}
			var parentBox = jQuery(selector);
			parentBox.find('.vscroller-up')
				.bind('mouseover',function(event){ focus_ui.vscroller.up( selector, speed ); })
				.bind('mouseout',function(event){ focus_ui.vscroller.stop(); })
				.css('display', 'none');
			parentBox.find('.vscroller-down')
				.bind('mouseover',function(event){ focus_ui.vscroller.down( selector, speed ); })
				.bind('mouseout',function(event){ focus_ui.vscroller.stop(); });			
		}, 
	
		move: function( mode, selector) {		
			var parentBox = jQuery(selector);
			var box = parentBox.find('.vscroller-mainbody');
			var max = box.attr('scrollHeight') - box.height();
			
			if (mode == 'down') {
				if ( box.scrollTop() == max ) {
					parentBox.find('.vscroller-down').css('display', 'none');
				}
				else {
					parentBox.find('.vscroller-up').css('display', '');
					box.scrollTop(box.scrollTop() + 1 );
				}										
			}
			else {
				if ( box.scrollTop() == 0) {
					parentBox.find('.vscroller-up').css('display', 'none');
				}
				else {	
					parentBox.find('.vscroller-down').css('display', '');
					box.scrollTop(box.scrollTop() - 1 );										
				}
			}
		},
		
		up: function( selector, speed ){
			focus_ui.vscroller.intval = setInterval("focus_ui.vscroller.move('up', '"+ selector +"')", speed );
		},
		
		down: function( selector, speed ){
			focus_ui.vscroller.intval = setInterval("focus_ui.vscroller.move('down', '"+selector+"')", speed );
		},
		
		stop: function(){
			window.clearInterval(focus_ui.vscroller.intval);
		}
	
	},				
	
	'dummy': ''
};
