$(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();
$('div.hideMe').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();
$('#formats img').css({'display':'inline','margin-right':'2px'});

//Set Cursor to Hand on URL Hover
$('#description h4, #formats img, .close, #plusLink, .dropCap, #corePics, #sidebarLeft img, #scheduleNew, #calculateMe').hover(
function() {
$(this).css("cursor","hand");
},
function() {
$(this).css("cursor","pointer");
}
);



//Get class registration id from alt of anchor - show relative div on Register Now! page
$('a.myPick').click(function(){ 
	$.cookie("myClassPick", $(this).attr("alt").val());
	var classPick = $.cookie("myClassPick");
	$('#classList').hide();
	$('div#+classPick+').show();
});

//Capture PACamount field value to post into monthly form when user selects Monthly Frequency
//$('#monthlyDonation').change(function() {
//$.cookie("PACamountTransfer", $('input[name=amount]').val());
//window.location = monthlyForm;
//});

//Autopopulate PACamount value on monthly form from donation form - when user selects Monthly Frequency
//var PACamount = $.cookie("PACamountTransfer");
//$('#PACamount').val(PACamount);


//Class Format Show/Hide
$('h2.allClasses').click(function() {
	$('div.hideMe').slideUp();
	$('#allClasses').slideDown();
});
$('h2.toningClasses').click(function() {
	$('div.hideMe').slideUp();
	$('#toningClasses').slideDown();
});

// ================ scripts for 2012 Registration Form ===================
//Table Filter
$(function() { 
  var theTable = $('table.filterMe')

  theTable.find("tbody > tr").find("td:eq(1)").mousedown(function(){
    $(this).prev().find(":checkbox").click()
  });

  $("#filter").keyup(function() {
    $.uiTableFilter( theTable, this.value );
  })

  $('#filter-form').submit(function(){
    theTable.find("tbody > tr:visible > td:eq(1)").mousedown();
    return false;
  }).focus(); //Give focus to input field
});  

// Add selection to field radio button onclick
$('input[name=home_class]:radio').click(function() {
	$mySelection = $(this).val();
	$('#myHomeClass').val($mySelection);

	$td = $(this).closest('tr').children('td');
	$classDetails = $td.eq(0).text() + ' | ';
	$classDetails += $td.eq(1).text() + ' | ';
	$classDetails +=  $td.eq(2).text() + ' | ';
	$classDetails +=  $td.eq(3).text() + ' | '; 
	$classDetails +=  $td.eq(4).text() + ' | '; 
	$classDetails +=  $td.eq(5).text() + ' | ';

        $('#myClassDetails').val($classDetails);

	$classFee =  $td.eq(2).text();

	if ( $classFee == "Group PT" ) {
		$myClassFee = 150;
		$myOptions = "You are eligible to select Upgrade Options";
	}
	else if ( $classFee == "Zumbatomic" ) {
		$myClassFee = 60;
		$myOptions = "No Upgrade Options Apply";
	}	
	else {
		$myClassFee = 100; 
		$myOptions = "You are eligible to select Upgrade Options";
	}
        $('#myClassFee').val($myClassFee);
	$('#upgradeOptions').val($myOptions);

});

// Add upgrade option if selected
$('#myUpgradeOptions').change(function() {
	$upgrade = $('#myUpgradeOptions').val();
	$upgrade = parseInt($upgrade);
	if ( $upgrade == "50" ) { 
		$('#sessionDouble').css("display","block");
		$('#motherDaughter').css("display","none");
	}
	else if ( $upgrade == "75" ) {
		$('#motherDaughter').css("display","block");
		$('#sessionDouble').css("display","none");
	}
	else {
		$('#sessionDouble').css("display","none");
		$('#motherDaughter').css("display","none");
	}
	$('#myUpgradeFee').val($upgrade);
});

// Add on Challenge if selected
$('#myChallengeOption').change(function() {
	$myChallenge = $('#myChallengeOption').val();
	$myChallenge = parseInt($myChallenge);

	$('#myChallengeFee').val($myChallenge);
});

// Double Challenge Fee for M-D Special
$('#motherDaughterChallenge').click(function() {

	$myChallenge = $('#myChallengeFee').val() * 2;
	$('#myChallengeFee').val($myChallenge);

});

// Calculate Total Registration Fee
$('#calculateMe').click(function() {

        $myClassFee = $('#myClassFee').val();
	$upgrade = $('#myUpgradeFee').val();
	$myChallenge = $('#myChallengeFee').val();

	$myTotal = parseInt($myClassFee) + parseInt($upgrade) + parseInt($myChallenge);

	$myTotal = ($myTotal * 1.13).toFixed(2);

	$('#myRegistrationFee').val($myTotal);

});

// Store Payment Option
$('#myPaymentOptions').change(function() {
	$myPayment = $('#myPaymentOptions').val();
	$('#myPaymentMethod').val($myPayment);
});

// ========================== END 2012 Registration scripts

// ========================== GPT Class Booking Script
// Add selection to field radio button onclick
$('input[name=mon]:radio').click(function() {
	$mySelection = $(this).val();
	$('#myMonClass').val($mySelection);
});
$('input[name=thu]:radio').click(function() {
	$mySelection = $(this).val();
	$('#myThuClass').val($mySelection);
});
$('input[name=sat]:radio').click(function() {
	$mySelection = $(this).val();
	$('#mySatClass').val($mySelection);
});



// ========================= ADMIN AREA SCRIPTS
//Change function for DB Select
$('#homeClassSelect').change(function(){
 var HC = $('#homeClassSelect').val();
 $('#HC').val(HC);
});





//Form input clear single field
$('#filter').val('');

//Table Sorter
$("#sessionFallTable, #myProfileTable").tablesorter(); 

//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','height':'34px','background':'url(http://www.myzumba.ca/myzumba-bullet.png) no-repeat left top'});

$('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','height':'34px','background':'url(http://www.myzumba.ca/myzumba-bullet.png) no-repeat left top'});
}
},
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','height':'34px','background':'url(http://www.myzumba.ca/myzumba-bullet.png) no-repeat left top'});
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') );
}
}
});


//Innerfade on bottom quotes and format pics
$('#ticker').innerfade({ animationtype: 'fade', speed: 2000, timeout: 10000, type: 'sequence', containerheight: '80px' });
$('#posterGallery').innerfade({ animationtype: 'fade', speed: 2000, timeout: 10000, type: 'sequence', containerheight: '600px' }); 


//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':'250px'
});
$('#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':'250px'
});
$('#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.myclear').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==""){
		hideAllErrorsContact();
		document.getElementById('contactNameError').style.display = 'inline';
		document.forms.contact.name.focus();		
		return false;	
	}
 	if(document.forms.contact.phone.value==""){		
		hideAllErrorsContact();
		document.getElementById('contactPhoneError').style.display = 'inline';		
		document.forms.contact.phone.focus();		
		return false;	
	}
 	if(document.forms.contact.email.value==""){
		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'
}
