/* Author: 

*/
$(document).ready(function(){
	/*******************************************************************************
	SCROLL TO TOP
	*******************************************************************************/
	var toTop=$("#toTop");
	if ($(window).scrollTop() == 0) {
		toTop.fadeOut(1000);
	}
	$(window).scroll(function() {
		if ($(this).scrollTop() != 0) {
			toTop.fadeIn();
		} else {
			toTop.fadeOut();
		}
	});
	toTop.click(function(event) {
		event.preventDefault();
		$("html,body").animate({scrollTop: 0},800);
	});

	$("a.group").fancybox({
		'titlePosition':'over',
		'hideOnContentClick': false
	});

	/*******************************************************************************
	PRINT PAGE
	*******************************************************************************/
	$( '.sharing ul' ).each( function( item ) {
		printUrl = function ( uniqueId, urlToPrint ) {
			$( 'body:first' ).append( '<iframe style="position:fixed;top:100;left:100;height:1px;width:1px;border:none;" id="printFrame-' + uniqueId + '" name="printFrame-' + uniqueId + '" src="' + urlToPrint + '" onload="frames[\'printFrame-' + uniqueId + '\'].focus();frames[\'printFrame-' + uniqueId + '\'].print();"></iframe>' )
		};
		$( this ).find( '.share-print a' ).click( function() {
			ref = $( this ).attr( 'href' );
			
			var do_print = function() {
				if ( ref.indexOf( '#print' ) == -1 ) {
					uid = new Date().getTime();
					printUrl( uid , ref );
				}
				else
					print();
			}
			if ( $( this ).parents( '.sharing-hidden' ).length > 0 ) {
				$( this ).parents( '.inner' ).slideUp( 0, function() {
					do_print();
				} );
			}
			else
				do_print();

			return false;
		} );
		
	} );

});

/*******************************************************************************
VALIDATE CONTACT FORM
*******************************************************************************/
$(function() { 
	$('#contact_form').validity(function() {
		$("#name")
			.require();
		$("#phone")
			.require()
			.match("phone");
		$("#email")
			.require()
			.match("email");
	});
});
// new output mode
(function(){
	$.validity.outputs.custom = {
		start:function(){ 
			$("input:text,tel,email")
			.css({border:'1px solid green'})
			.removeClass('fail');
		},
		end:function(results) { 
			if (!results.valid && $.validity.settings.scrollTo) {
				location.hash = $(".fail:eq(0)").attr('id')
			}
		},
		raise:function($obj, msg){
			alert(msg);
			$obj
			.css({borderColor:'red'})
			.addClass('fail');
		},
		// Our aggregate raise will just raise the error on the last input:
		raiseAggregate:function($obj, msg){ 
			this.raise($($obj.get($obj.length - 1)), msg); 
		}
	}
})();
$.validity.setup({ outputMode:'custom' });

/*******************************************************************************
SWFOBJECT EMBED THE WCCO VIDEO ON HOMEPAGE
*******************************************************************************/
var params = { allowfullscreen: "true", allowScriptAccess: "always" };
var atts = { id: "myytplayer" };
swfobject.embedSWF("http://www.youtube.com/e/OK8bRDZG7OI?enablejsapi=1&playerapiid=ytplayer&rel=0", "ytapiplayer", "320", "267", "8", null, null, params, atts);
/*
var flashvars = {};
var params = {};
var attributes = {};

params.quality = "autolow";
params.play = "true";
params.loop = "true";
params.scale = "showall";
params.wmode = "opaque";
params.bgcolor = "#ffffff";
params.allowfullscreen = "true";
params.allowscriptaccess = "always";

flashvars.height = "264";
flashvars.width = "320";
flashvars.file = "http://www.amundsonviolin.com/wcco_interview.flv";
flashvars.image = "http://www.amundsonviolin.com/img/wcco_interview_poster_frame.jpg";
flashvars.searchbar = "false";
flashvars.showdigits = "false";
flashvars.usefullscreen = "false";

attributes.id = "mpl";
attributes.name = "mpl";
attributes.align = "middle";
swfobject.embedSWF (
	"http://www.jeroenwijering.com/embed/player.swf",
	"player",
	"320","264","9.0.0",false,
	flashvars,params,attributes
);
*/

/*******************************************************************************
Scramble
*******************************************************************************/
$('span.mail').nospam();
$('a.mail').nospam({ replaceText: true });
$('a.contact').nospam({});

