jQuery(function( $ ){

	$('#content').attr({scrollTop:0,scrollLeft:0});
	$.localScroll.hash({
		target: '#content', //could be a selector or a jQuery object too.
		axis:'xy',//the default is 'y'
		queue:true,
		duration:1500
	});

	var $last = $([]);//save the last link
	$.localScroll({
		target: '#content', //could be a selector or a jQuery object too.
		axis:'xy', //the default is 'y'
		queue:true,
		duration:1000,
		hash:false,
		onBefore:function( e, anchor, $target ){//'this' is the clicked link
			$last.removeClass('scrolling');
			$last = $(this).addClass('scrolling');
			if( this.blur )
				this.blur();//remove the awful outline
		},
		onAfter:function( anchor ){
			$last.removeClass('scrolling');
		}
	});
	
    $('#Gallery').flash(
        { src: './slideshow.swf',
          width: 924,
          height: 348},
        { version: 8 }
    );


	$(".content").hide();
	$(".active").show();
	$('<img src="./images/arrow-down.gif" class="arrow" />').insertBefore('h5 a'); 				   
	$("h5 a").click(function(){
		if($(this).is(".active")) {
         $(this).toggleClass("active");
		 $('.arrow.active').attr('src','./images/arrow-down.gif'); // change the image src of the current ACTIVE image to have an INACTIVE state.
         $(this).parent().next(".content").slideToggle();
         return false;
		} else {
			$(".content:visible").slideUp("slow"); // close all visible divs with the class of .content
			$("h5 a.active").removeClass("active");  // remove the class active from all h5's with the class of .active
			$(this).toggleClass("active");
			$('.arrow.active').attr('src','./images/arrow-down.gif'); // change the image src of the current ACTIVE image to have an INACTIVE state.
			$(".arrow").addClass('active');
			$(this).siblings('.arrow.active').attr('src','./images/arrow-right.gif'); // change the image src of the new active image to have an active state.
			$(this).parent().next(".content").slideToggle();
			return false;
		}
	});


// External Link

	$("a[href^='http']").not("[href*='musiclesson4u.com']").attr('target','_blank');



//Contact Form
  $('.error').hide();
  $("#jQsubmit").click(function() {
	$("#jQsubmit").attr("disabled","true").attr("value", "Sending, please wait...");
	$(".error").hide();
	var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
	
	var jQname = $("#jQname").val();
	if(jQname == '') {
		$("#jQname").after('<label class="error">This field is required.</label>');
		$("#jQsubmit").removeAttr("disabled").attr("value", "Send Email"); 
		return false;
	} 
	
	var jQemail = $("#jQemail").val();
	if(jQemail == '') {
		$("#jQemail").after('<label class="error">This field is required.</label>');
		$("#jQsubmit").removeAttr("disabled").attr("value", "Send Email"); 
		return false;
	} else if(!emailReg.test(jQemail)) {	
		$("#jQemail").after('<label class="error">Please enter a valid email address.</label>');
		$("#jQsubmit").removeAttr("disabled").attr("value", "Send Email"); 
		return false;
	}
	
	var jQcomment = $("#jQcomment").val();
	if(jQcomment == '') {
		$("#jQcomment").after('<label class="error">You forgot to enter the message.</label>');
		$("#jQsubmit").removeAttr("disabled").attr("value", "Send Email"); 
		return false;
	}	
	
	var dataString = $("#jQcontactForm form").serialize();
	//alert (dataString);return false;
		
	$.ajax({
	type: "post",
	url: "/send.asp",
	data: dataString,
	error: function() {
		$('#cForm').html("<div id='message'></div>");
        $('#message').html("<img src='../images/error.gif' alt='failed' /><h5 class='error'>Failed to Submit!</h5>")
        .append("<span>Please try to send your emails to: sako [at] musiclesson4u.com</span>")
        .hide()
        .fadeIn(1500, function() {
          $('#message');
        });
	},
    success: function() {
		$('#cForm').html("<div id='message'></div>");
        $('#message').html("<img src='../images/sent.gif' alt='sent' /><h5>Contact Form Submitted!</h5>")
        .append("<span>We will be in touch soon.</span>")
        .hide()
        .fadeIn(1500, function() {
          $('#message');
        });
	 }
	});
    return false;
	});
});

function go2Gallery() {
   top.location.href = "#Gallery";
}
unique = 0;

function resizeTitle(objectID,newHeight){
	$("#"+objectID).attr("height",newHeight);
}
function replaceTitle(selector,src,size,color,background){
	color = color == undefined ? "#e4e4e4" : color;
	$(selector).flash(
		{ 
			src: src, 
			flashvars: { 
				css: [
					'* { color: '+color+'; font-size: '+size+'px;}',
					'a { color: #999; text-decoration: none; }',
					'a:hover { text-decoration: none; }'
				].join(' '),
				objectID: "flashText"+unique
			},
			id: "flashText"+unique
		},
		{ update: false },
		function(htmlOptions) {
			htmlOptions.flashvars.txt = this.innerHTML;
			htmlOptions.flashvars.objectID = "flashText"+unique;
			this.innerHTML = '<div>'+this.innerHTML+'</div>';
			unique++;
			var $alt = $(this.firstChild);
			if (background != undefined){
				htmlOptions.bgcolor = background;
			}
			htmlOptions.height = $alt.height();
			htmlOptions.width = $alt.width();
			$alt.addClass('alt');
			$(this)
				.addClass('flash-replaced')
				.prepend($.fn.flash.transform(htmlOptions));						
		}
	);	
}
function replaceAllTitles(){
	replaceTitle("h2.flashTitle",'./h2titles.swf',42,"#879fbb");
	replaceTitle("h2.flashLink",'./h2titles.swf',32,"#006600");
}
AudioPlayer.setup("player.swf", {width: 220});