$(document).ready(function() {

//Hide elements
$('#description').hide();
$('#formatsPlus').hide();
$('#corePics').hide();
$('#corePics img').hide();
$('#toningPics img').hide();
$('#toningPics').hide();
$('#toningPicsLink').hide();
$('#quickReg').hide();
$('#contactForm').hide();
$('#pricing').hide();
$('#schedule').hide();
$('#schedule2011').hide();
//$('#copyright').hide();
$('#location-maps').hide();
$('#location-maps img').hide();


//Set element attributes
$('#leftBottom img').css({'float':'left','margin-top':'15px'});
$('#copyright img').css({'float':'left','margin-bottom':'10px'});
$('#pricing img').css("float","right");
//$('#sidebarLeft li:eq(6)').css({'marginTop':'10px'});
$('#leftTop p').css({'margin-top':'20px','background':'#fff'});
$('#leftTop h2').css({'text-align':'right','font-size':'1.5em'});
$('#mainNav li:eq(6)').css({'marginTop':'10px','lineHeight':'3.0em','background':'url(http://www.myzumba.ca/images/quick-contact.png) no-repeat'});
$('#sidebarLeft img').css({'background':'#fff'});
$('#location-maps img').css({'float':'left','margin-right':'10px'});
$('#location-maps img:eq(0)').show();


//Set Cursor to Hand on URL Hover
$('#description h4, #formats img, .close, #plusLink, .dropCap, #corePics, #sidebarLeft img, #scheduleNew').hover(
function() {
$(this).css("cursor","hand");
},
function() {
$(this).css("cursor","pointer");
}
);


//Show Hide Elements
$("div.showHide p").hover(function() {
$(this).addClass("hovered");
},
function() {
$(this).removeClass("hovered");
});

//Show Hide Toggle Function
$('div.showHide > p, div.showHide ul, div.showHide hr').hide();
$('div.showHide > h2').css({'cursor':'pointer','paddingLeft':'50px','background':'url(../images/icon-more.png) no-repeat left 50%'});

$('div.showHide').toggle(function() {

if ( $('p',this).is(':visible') ) {
 $('p',this).show();
}

else {
$('div.showHide > p, div.showHide ul, div.showHide hr').hide();
$('p,ul,li,img,hr', this).slideDown('fast');
$('h2', this).css({'cursor':'pointer','paddingLeft':'50px','background':'url(../images/icon-close.png) no-repeat left 50%'});
}
},
function() {

if ( $('p',this).hasClass('hovered') ) {
 $('p',this).show();
}

else {
$('p,ul,li,img,hr', this).slideUp('slow');
$('h2', this).css({'cursor':'pointer','paddingLeft':'50px','background':'url(../images/icon-more.png) no-repeat left 50%'});
if ( $('p>a',this).attr('href').length != 0 && $('p>a',this).hasClass('hovered') ) {
 window.open( $('p>a.hovered',this).attr('href') );
}
if ( $('li>a',this).attr('href').length != 0 && $('li>a',this).hasClass('hovered') ) {
 window.open( $('li>a.hovered',this).attr('href') );
}
}
});


//QuickReg Hover
$('#footerNav li:eq(2)').hoverIntent(
function() {
$(this).stop(true).css("cursor","hand");

if ($('#contactForm, #pricing, #location-maps').is(':visible')) {
$('#contactForm').fadeOut().animate({'top':'-20px'},{duration: '2000', queue: false});
$('#pricing, #location-maps').hide();
$('#quickReg').fadeIn('slow').animate({'top':'-330px'}, {
duration: '2000',
queue: false});
} else {
$('#quickReg').fadeIn('slow').animate({'top':'-330px'}, {
duration: '2000',
queue: false});
}
},
function() {
$(this).stop(true).css("cursor","pointer");
}
);

//General close function
$('.close').click(function() {
if ($('#quickReg').is(':visible')) {
$('#quickReg').fadeOut().animate({'top':'-20px'},{duration: '2000', queue: false});
}  
if ($('#contactForm').is(':visible')) {
$('#contactForm').fadeOut().animate({'top':'-20px'},{duration: '2000', queue: false});
}
if ($('#pricing').is(':visible')) {
$('#pricing').fadeOut();
} 
if ($('#location-maps').is(':visible')) {
$('#location-maps').fadeOut();
} 
if ($('#formatsPlus').is(':visible')) {
$('#formatsPlus').animate({'top':'400px','width':'5px'},{duration: '2000', queue: false}).fadeOut();
$('#corePics').fadeOut();
} else {
$(this).parent().fadeOut();
}
});


//Show class format description
$('#formats img').click(function() {
var classType = $(this).attr("src");

if (classType == "images/zumba-toning.png") {
var imgDes = $(this).attr("longdesc");
$('#innerDesc').html(imgDes);
$(this).prependTo('#innerDesc');
$('#innerDesc img').css({
'float':'left',
'margin-bottom':'150px'
});
$('#rightTop .inner h2, #formats').hide();
$('#description').css({'width':'90%'});
$('#description').slideDown('slow').fadeIn('fast');
$('#toningPicsLink').fadeIn();
} 

else {
var imgDes = $(this).attr("longdesc");
$('#innerDesc').html(imgDes);
$(this).prependTo('#innerDesc');
$('#innerDesc img').css({
'float':'left',
'margin-bottom':'150px'
});
$('#rightTop .inner h2, #formats').hide();
$('#description').css({'width':'90%'});
$('#description').slideDown('slow').fadeIn('fast');
}
});

//Return to List of Class Formats
$('#description h4').click(function() {
$('#innerDesc img').appendTo('#formats');
$('#innerDesc').empty();
$('#description, #toningPicsLink').hide();
$('#formats').slideUp().fadeIn();
$('#rightTop .inner h2').show();
});

//Plus click function
$('#plusLink').click(function() {
if ($('#quickReg, #contactForm').is(':visible')) {
$('#quickReg').fadeOut().animate({'top':'-20px'},{duration: '2000', queue: false});
$('#contactForm').fadeOut().animate({'top':'-20px'},{duration: '2000', queue: false});
$('#formatsPlus').fadeIn('slow').animate({'top':'320px','width':'550px'}, {duration: '2000', queue: false});
return false;
}
if ($('#location-maps').is(':visible')) {
$('#location-maps').animate({'width':'50px'},{duration: '3000', queue: false}).fadeOut();
$('#formatsPlus').fadeIn('slow').animate({'top':'320px','width':'550px'}, {duration: '2000', queue: false});
return false;
}
if ($('#pricing').is(':visible')) {
$('#pricing').animate({'width':'50px'},{duration: '3000', queue: false}).fadeOut();
$('#formatsPlus').fadeIn('slow').animate({'top':'320px','width':'550px'}, {duration: '2000', queue: false});
return false;
} 
else {
$('#formatsPlus').fadeIn('slow').animate({'top':'-100px','width':'550px'}, {duration: '2000', queue: false});
}
});


//Main Nav Functions

function hideAllDivs() {
$('#toningPicsLink').hide();
$('#classformats').hide();
$('#schedule').hide();
$('#location-maps').hide();
$('#pricing').hide();
$('#contactForm').hide();
$('#quickReg').hide();
$('#schedule2011').hide();
}

//Class Formats Click function
$('#mainNav li:eq(0)').click(function() {
hideAllDivs();
$('#classformats').fadeIn();
return false;
});

//Class Schedule Click function
$('#mainNav li:eq(1)').click(function() {
hideAllDivs();
$('#schedule').fadeIn();
return false;
});

//2011 Class Schedule Click function
$('#scheduleNew').click(function() {
hideAllDivs();
$('#schedule2011').fadeIn();
return false;
});

//Location Maps Click function
$('#mainNav li:eq(2)').click(function() {
hideAllDivs();
$('#location-maps').fadeIn();
return false;
});

//Pricing Click function
$('#mainNav li:eq(3)').click(function() {
hideAllDivs();
$('#pricing').fadeIn();
return false;
});


//Contact Form Hover
$('#mainNav li:eq(6)').hoverIntent(function() {
 $(this).stop(true).css({'cursor':'hand'});
 hideAllDivs();
 $('#contactForm').fadeIn('slow').animate({'top':'-370px'}, {duration: '2000', queue: false});
 $('#quickReg').fadeIn('slow').animate({'top':'-335px'}, {duration: '2000', queue: false});
},
function() {
$(this).stop(true).css("cursor","pointer");
}
);


//Enews Sign Up Click function
$('#sidebarLeft img:eq(0)').click(function() {
window.location = "http://www.myzumba.ca/enews/march-2011.htm";
return false;
});

//Facebook Click function
$('#sidebarLeft img:eq(1)').click(function() {
window.location = "http://www.facebook.com/pages/Markham-ON/MyZumbaFitness/126258924073473";
return false;
});

//Toning Pics Click function
$('.toningPics').click(function() {
$('#toningPics').fadeIn();
return false;
});

//ToningPics Close Click function
$('#toningPics').click(function() {
$('#toningPics').fadeOut();
return false;
});


//Core Pics Click function
$('#formatsPlus .corePics').click(function() {
$('#corePics').fadeIn();
return false;
});

//Core Pics Close Click function
$('#corePics img').click(function() {
$('#corePics').fadeOut();
return false;
});

//Crossfade Slideshow
slideShowCore();
function slideShowCore() {
var current = $('#corePics .show');
var next = current.next().length ? current.next() : current.parent().children(':first');

current.hide().removeClass('show');
next.fadeIn('slow').addClass('show');
setTimeout(slideShowCore, 4000);
}
slideShowToning();
function slideShowToning() {
var current = $('#toningPics .show');
var next = current.next().length ? current.next() : current.parent().children(':first');

current.hide().removeClass('show');
next.fadeIn('slow').addClass('show');
setTimeout(slideShowToning, 4000);
}


//Enews click function
$('#enews p.zumbawear').click(function() {
$('#zumbawear').fadeIn();
return false;
});

$('#zumbawear').click(function() {
$('#zumbawear').fadeOut();
return false;
});


//Location-maps Detail click function
$('#location-maps span:eq(0)').click(function() {
$('#location-maps img').hide();
$('#location-maps img:eq(0)').fadeIn('slow');
});

$('#location-maps span:eq(1)').click(function() {
$('#location-maps img').hide();
$('#location-maps img:eq(1)').fadeIn('slow');
});

$('#location-maps span:eq(2)').click(function() {
$('#location-maps img').hide();
$('#location-maps img:eq(2)').fadeIn('slow');
});

$('#location-maps span:eq(3)').click(function() {
$('#location-maps img').hide();
$('#location-maps img:eq(3)').fadeIn('slow');
});

$('#location-maps span:eq(4)').click(function() {
$('#location-maps img').hide();
$('#location-maps img:eq(4)').fadeIn('slow');
});

$('#location-maps span:eq(5)').click(function() {
$('#location-maps img').hide();
$('#location-maps img:eq(5)').fadeIn('slow');
});

$('#location-maps span:eq(6)').click(function() {
$('#location-maps img').hide();
$('#location-maps img:eq(6)').fadeIn('slow');
});

$('#location-maps span:eq(7)').click(function() {
$('#location-maps img').hide();
$('#location-maps img:eq(7)').fadeIn('slow');
});

$('#location-maps span:eq(8)').click(function() {
$('#location-maps img').hide();
$('#location-maps img:eq(8)').fadeIn('slow');
});

$('#location-maps span:eq(9)').click(function() {
$('#location-maps img').hide();
$('#location-maps img:eq(9)').fadeIn('slow');
});


//Table Row Highlight Function
$(".schedule tr").mouseover(function(){$(this).addClass("over");}).mouseout(function(){$(this).removeClass("over");});

$('#ticker ul').innerfade({
speed: 'slow',
timeout: 4000,
type: 'sequence',
containerheight: '200px'
});

//Form input clear and reset function
$('input.clear').each(function() {
$(this)
.data('default', $(this).val())
.addClass('inactive')
.focus(function() {
$(this).removeClass('inactive');
if ($(this).val() == $(this).data('default') || '') {
$(this).val('');
}
})
.blur(function() {
var default_val = $(this).data('default');
if ($(this).val() == '') {
$(this).addClass('inactive');
$(this).val($(this).data('default'));
}
});
});


//Form input hide required field error if field not empty
$('input.required').each(function() {
$(this).blur(function() {
if ($(this).val() != '') {
hideAllErrorsRegistration();
}
});
});


//place class value into classSelection

$('input[name=myClass]').click(function() {
	var checkedValue = $('input[name=myClass]:checked').val();
	$('#classSelection').val(checkedValue);
});



//closing tags for document ready function
});

//Form Validation Script
function validateFormRegister() {
	if(document.forms.register.QRname.value=="Enter Your Full Name"){
		hideAllErrorsRegister();
		document.getElementById('regNameError').style.display = 'inline';
		document.forms.register.QRname.focus();		
		return false;	
	}
 	if(document.forms.register.email.value=="Enter Your Email Address"){
		hideAllErrorsRegister();
		document.getElementById('regEmailError').style.display = 'inline';		
		document.forms.register.email.focus();		
		return false;	
	}
 	if(document.forms.register.classdaytime.value=="Select Desired Class"){		
		hideAllErrorsRegister();
		document.getElementById('regClassdaytimeError').style.display = 'inline';		
		document.forms.register.classdaytime.focus();		
		return false;	
	}
}

function hideAllErrorsRegister() {
	document.getElementById('regNameError').style.display = 'none'
	document.getElementById('regEmailError').style.display = 'none'
	document.getElementById('regClassdaytimeError').style.display = 'none'
}

function validateFormContact() {
	if(document.forms.contact.name.value=="Enter Your Full Name"){
		hideAllErrorsContact();
		document.getElementById('contactNameError').style.display = 'inline';
		document.forms.contact.name.focus();		
		return false;	
	}
 	if(document.forms.contact.phone.value=="Enter Your Phone Number"){		
		hideAllErrorsContact();
		document.getElementById('contactPhoneError').style.display = 'inline';		
		document.forms.contact.phone.focus();		
		return false;	
	}
 	if(document.forms.contact.email.value=="Enter Your Email Address"){
		hideAllErrorsContact();
		document.getElementById('contactEmailError').style.display = 'inline';		
		document.forms.contact.email.focus();		
		return false;	
	}
}

function hideAllErrorsContact() {
	document.getElementById('contactNameError').style.display = 'none'
	document.getElementById('contactPhoneError').style.display = 'none'
	document.getElementById('contactEmailError').style.display = 'none'
}


//Main Registration Form
function validateFormMYRegistration() {
	if(document.forms.registration.name.value==""){
		hideAllErrorsMYRegistration();
		document.getElementById('contactNameError').style.display = 'inline';
		document.forms.registration.name.focus();		
		return false;	
	}
	if(document.forms.registration.address.value==""){
		hideAllErrorsMYRegistration();
		document.getElementById('contactAddressError').style.display = 'inline';
		document.forms.registration.address.focus();		
		return false;	
	}
 	if(document.forms.registration.email.value==""){
		hideAllErrorsMYRegistration();
		document.getElementById('contactEmailError').style.display = 'inline';		
		document.forms.registration.email.focus();		
		return false;	
	}
 	if(document.forms.registration.phone.value==""){		
		hideAllErrorsMYRegistration();
		document.getElementById('contactPhoneError').style.display = 'inline';		
		document.forms.registration.phone.focus();		
		return false;	
	}
 	if(document.forms.registration.classSelection.value==""){		
		hideAllErrorsMYRegistration();
		document.getElementById('classSelectionError').style.display = 'inline';		
		document.forms.registration.classSelection.focus();		
		return false;	
	}
}

function hideAllErrorsMYRegistration() {
	document.getElementById('contactNameError').style.display = 'none'
	document.getElementById('contactPhoneError').style.display = 'none'
	document.getElementById('contactEmailError').style.display = 'none'
	document.getElementById('contactAddressError').style.display = 'none'
	document.getElementById('classSelectionError').style.display = 'none'
}







//Special settings for Groupon
function validateFormRegistration() {
	if(document.forms.registration.name.value==""){
		hideAllErrorsRegistration();
		document.getElementById('contactNameError').style.display = 'inline';
		document.forms.registration.name.focus();		
		return false;	
	}
	if(document.forms.registration.address.value==""){
		hideAllErrorsRegistration();
		document.getElementById('contactAddressError').style.display = 'inline';
		document.forms.registration.address.focus();		
		return false;	
	}
 	if(document.forms.registration.email.value==""){
		hideAllErrorsRegistration();
		document.getElementById('contactEmailError').style.display = 'inline';		
		document.forms.registration.email.focus();		
		return false;	
	}
 	if(document.forms.registration.phone.value==""){		
		hideAllErrorsRegistration();
		document.getElementById('contactPhoneError').style.display = 'inline';		
		document.forms.registration.phone.focus();		
		return false;	
	}
 	if(document.forms.registration.grouponNum.value==""){		
		hideAllErrorsRegistration();
		document.getElementById('grouponNumError').style.display = 'inline';		
		document.forms.registration.grouponNum.focus();		
		return false;	
	}
 	if(document.forms.registration.classSelection.value==""){		
		hideAllErrorsRegistration();
		document.getElementById('classSelectionError').style.display = 'inline';		
		document.forms.registration.classSelection.focus();		
		return false;	
	}
}

function hideAllErrorsRegistration() {
	document.getElementById('contactNameError').style.display = 'none'
	document.getElementById('contactPhoneError').style.display = 'none'
	document.getElementById('contactEmailError').style.display = 'none'
	document.getElementById('contactAddressError').style.display = 'none'
	document.getElementById('grouponNumError').style.display = 'none'
	document.getElementById('classSelectionError').style.display = 'none'
}
