jQuery(document).ready(function($){
	// INIT Menu
	$("ul.sf-menu").supersubs({ 
		minWidth: 12,
		maxWidth: 27,
		extraWidth: 1
	}).superfish();
	
	$('a.unavailable').cluetip({
		splitTitle: '|',
		activation: 'hover',
		cluezIndex: 10000,
		topOffset: 0,
		leftOffset: 15,
		positionBy: 'mouse',
		tracking: true,
		mouseOutClose: true,
		arrows: true,
		fx: {             
			open: 'fadeIn', // can be 'show' or 'slideDown' or 'fadeIn'
			openSpeed:  ''
		},
		hoverIntent: {    
			sensitivity:  3,
			interval:     300,
			timeout:      5
    	}
	});
	
	// INIT Carousel
	$('#carousel').jcarousel({
		scroll: 1,
		auto: 5,
		wrap: 'last',
		initCallback: function (carousel) {
			// Disable autoscrolling if the user clicks the prev or next button.
			$('.jcarousel-control a').bind('click', function() {
				carousel.scroll($(this).text());
				return false;
			});
		
			// Pause autoscrolling if the user moves with the cursor over the clip.
			carousel.clip.hover(
				function() {
					carousel.stopAuto();
				},
				function() {
					carousel.startAuto();
				}
			);
		},
		itemVisibleInCallback: {
			onBeforeAnimation: function() {
				
			},
			onAfterAnimation: function(carousel, item, idx, state) {
		
    			// idx is the number of the visible item
    			// Change the button who's rel is the idx to the selected state
    			$('.jcarousel-control a').removeClass('selected');
    			$('.jcarousel-control a[rel=' + idx + ']').addClass('selected');
			}
		},
		buttonNextHTML: null,
		buttonPrevHTML: null
	});

	// INIT Create Login Form
	$('#createloginform').dialog({
		autoOpen: false,
		bgiframe: true,
		modal: true,
		resizable: false,
		draggable: false,
		buttons: {
			"Cancel": function(){
				$(this).dialog("close");
			},
			"Submit": function(){
				$(this).dialog("close");
			}
		}
	});
		
	// INIT Page Unavailable
	$('#learnmoreform').dialog({
		autoOpen: false,
		bgiframe: true,
		modal: true,
		width: '650px',
		resizable: false,
		dialogClass: 'aadialog',
		draggable: false,
		buttons: {
			"OK": function(){
				$(this).dialog("close");
			}
		}
	});
	 
	/*// Login Event Handler
	$('#createlogin').click(function(e){
		e.preventDefault();
		$('#createloginform').dialog('open');
	});*/
	
	$('.unavailable').click(function(e){
		e.preventDefault();
	});
	
	$('#learnmore').click(function(e){
		e.preventDefault();
		$('#learnmoreform').dialog('open');
	});
	
	// Clears the inputs if necessary
	$('#login input[type=text]').focus(function(){
		if (($(this).val() == 'Username') || ($(this).val() == 'Password')) {
			$(this).val('');
		}
	});
	
	// Put the default values back if necessary
	$('#login input[type=text]').blur(function(){
		if ($(this).val()=='') {
			$(this).val($(this).attr('rel'));	
		}
	});
	
	// Clears the inputs if necessary
	$('#login input[type=password]').focus(function(){
		if (($(this).val() == 'Username') || ($(this).val() == 'Password')) {
			$(this).val('');
		}
	});
	
	// Put the default values back if necessary
	$('#login input[type=password]').blur(function(){
		if ($(this).val()=='') {
			$(this).val($(this).attr('rel'));	
		}
	});
});