/**
 * Scallys Javascript Controller
 *
 * Author:	Eoghan O'Brien
 * Created:	27/04/10
 * 
 */
var Scallys;

(function($)
{

	Scallys = {
		version: '0.1',
		website: 'http://www.supervaluclon.ie/',
		init: function()
		{
			/**
			 * Start any plugins and dom ready events in this
			 * in this method.
			 */
			Scallys.colorBox();
			Scallys.scrollPane();
			Scallys.menuControl();
			Scallys.Utilities.external();
			Scallys.Forms.focus();
		},
		Utilities:
		{
			external: function() {
				$('A[rel*="external"]').click(function(e) {
					var url = $(this).attr('href');
					window.open(url);
					e.preventDefault();
				});
			}
		},
		Forms:
		{
			focus: function() {
				var prevLabel = '';
				$('.focus').focus(function() {
					if ( $.trim($(this).val()) == $(this).attr('title') ) {
						prevLabel = $(this).val();
						$(this).val('');
					}
				});
				$('.focus').blur(function() {
					if ( $(this).val() == '' ) {
						$(this).val(prevLabel);
					}
				});
			}
		},
		scrollPane: function()
		{
			if ( $('.scroll-pane').length > 0 ) {
				$('.scroll-pane').jScrollPane();
			}
		},
		colorBox: function()
		{
			if ( $('.colorbox').length > 0) {
				$('.colorbox').colorbox({width:"30%", height:"20%", iframe:true});
			}
		},
		menuControl: function()
		{
			var ul = $('.menu-control');
			var togglers = $('.toggle', ul);
			togglers.parent().find('ul').slideUp();
			
			togglers.click(function(e) {
				//$()
				$(this).parent().find('ul', $(this)).slideToggle('slow');
				e.preventDefault();
			});
		}
	}

	$(function() {
		Scallys.init();
	});

})(jQuery.noConflict());
