$(function() {
	var volume = 1;
	$(document).pngFix();

	$('#play a').colorbox({
		iframe:true,
		innerWidth:425,
		innerHeight:344,
		onOpen:function(){
			volume = $("#jquery_jplayer_1").data("jPlayer").status.volume;
			$("#jquery_jplayer_1").jPlayer("volume", 0);
		},
		onClosed:function(){ $("#jquery_jplayer_1").jPlayer("volume", volume); }
	});

	$('#scrollableContent .album a.play').colorbox({
		iframe:true,
		innerWidth:425,
		innerHeight:344,
		onOpen:function(){
			volume = $("#jquery_jplayer_1").data("jPlayer").status.volume;
			$("#jquery_jplayer_1").jPlayer("volume", 0);
		},
		onClosed:function(){ $("#jquery_jplayer_1").jPlayer("volume", volume); }
	});

	$('#scrollableContent a.enlarge').colorbox();

	// $('.contact a').click( function(event) {
		// event.preventDefault();
		$('.contact a').colorbox({
			inline: true,
			href: "#contactWrapper",
			width: '706px',
			height: '418px',
			// data: 'http://www.arigold.com/contact',
			onComplete: function(){
				$('.contact-form .error').hide();

				/* Contact Form */
				$(".contact-form .submitbutton").click(function() {
					// hide error messages
					$('.contact-form .error').hide();

					// check if the value for name is not empty or not equal to default value
					var name = $(".contact-form input#name").val();
					if (name == "" || name =="Name") {
						$(".contact-form label#name_error").fadeIn('slow');
						$(".contact-form input#name").animate({ backgroundColor: '#ffffbb'}, 1000);
						$(".contact-form input#name").focus();
						return false;
					}

					// check if the value for email is not empty or not equal to default value
					var email = $(".contact-form input#email").val();
					var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;

					if (email == "" || email == "your.email@domain.com") {
						$(".contact-form label#email_error").fadeIn('slow');
						$(".contact-form input#email").animate({ backgroundColor: '#ffffbb'}, 400);
						$(".contact-form input#email").focus();
						return false;
					}
					// test if the value for email is a valid email address
					else if(!emailReg.test(email)) {
						$(".contact-form label#email_error2").fadeIn('slow');
						$(".contact-form input#email").animate({ backgroundColor: '#ffffbb'}, 400);
						$(".contact-form input#email").focus();
			    		return false;
					}

					// check if the value for message is not empty or not equal to default value
					var message = $(".contact-form textarea#comments").val();
					if (message == "") {
					    $(".contact-form label#comments_error").fadeIn('slow');
					    $(".contact-form textarea#comments").animate({ backgroundColor: '#ffffbb'}, 400);
						$(".contact-form textarea#comments").focus();
						return false;
					}

					var str = $("form.contact-form").serialize();

					$.ajax({
						type: "POST",
						url: "/include/contact.php",
						data: str,

						success: function(msg){
							$("#note").ajaxComplete(function(event, request, settings) {
								$("#note").show();
								if(msg == 'OK'){
									result = '<span class="notification_ok">Your message has been sent.<br />We will be in touch soon.</span>';
									$("#fields").hide();
								} 
								else {
									result = '<span class="notification_error">Error submitting form.</span>';
									$("#fields").hide();
								}
								$(this).html(result);
							});
						}
					});
					return false;

				});
			}
		});

	// });

	$('#photoContent').jScrollPane();
	$('#scrollableContent').jScrollPane();
	$('#comments').jScrollPane({autoReinitialise: true});
	$('#merchandiseContent').jScrollPane({autoReinitialise: true});

	var url = 'http://www.sirarigold.com/';
	$('.share').hover( function() {
		url = $(this).attr('href');
		$(this).ishare({
			shareurl: url,
			tweets: false,
			fbLikebox: false,
			targetBlank: true,
			iconsDir: 'http://www.arigold.com/include/javascript/ishare/icons/'
		});
	});

	$('#footerMedia').jCarouselLite({
        btnNext: ".footerNext",
        btnPrev: ".footerPrev",
		mouseWheel: true,
		visible: 4,
	    speed: 800,
	    auto: 1000
    });

	$('#footerMedia li.youtube a').colorbox({
		iframe:true,
		innerWidth:425,
		innerHeight:344,
		onOpen:function(){
			volume = $("#jquery_jplayer_1").data("jPlayer").status.volume;
			$("#jquery_jplayer_1").jPlayer("volume", 0);
		},
		onClosed:function(){ $("#jquery_jplayer_1").jPlayer("volume", volume); }
	});

	$('#jukeboxToggle a').mouseenter( function(event) {
		event.preventDefault();
		if ($('#jukebox').is(':hidden')) {
			$('#jukebox').slideDown(400);
		}
	});

	$('#jukeboxWrapper').mouseleave( function(event) {
		event.preventDefault();
		$('#jukebox').slideUp(400);
	});

	$('#contentControls .subscribe').click( function(event) {
		event.preventDefault();
		if ($('#connectBarWrapper').is(':hidden')) {
			$('#connectBarWrapper').slideDown(400);
		} else {
			$('#connectBarWrapper').slideUp(400);
		}
	});

	$('#connectBarShow').click( function(event) {
		event.preventDefault();
		if ($('#connectBarWrapper').is(':hidden')) {
			$('#connectBarWrapper').slideDown(400);
		} else {
			$('#connectBarWrapper').slideUp(400);
		}
	});

	$('#connectBarHide').click( function(event) {
		event.preventDefault();
		$('#connectBarWrapper').slideUp(400);
	});

	/* Subscribe Form */

	$('.subscribe-form .error').hide();

	$(".subscribe-form .submitbutton").click(function() {
		// hide error messages
		$('.subscribe-form .error').hide();

		var email = $(".subscribe-form input#email").val();
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;

		// check if the value for email is not empty or not equal to default value
		if (email == "" || email == "your.email@domain.com") {
			$(".subscribe-form label#email_error").fadeIn('slow');
			$(".subscribe-form input#email").animate({ backgroundColor: '#ffffbb'}, 400);
			$(".subscribe-form input#email").focus();
			return false;
		}
		// test if the value for email is a valid email address
		else if(!emailReg.test(email)) {
			$(".subscribe-form label#email_error2").fadeIn('slow');
			$(".subscribe-form input#email").animate({ backgroundColor: '#ffffbb'}, 400);
			$(".subscribe-form input#email").focus();
    		return false;
		}

		var str = $("form.subscribe-form").serialize();

		$.ajax({
			type: "POST",
			url: "/ari/include/subscribe.php",
			data: str,

			success: function(msg){
				$("#sf-note").ajaxComplete(function(event, request, settings) {
					$("#sf-note").show();
					if(msg == 'OK'){
						result = '<span class="notification_ok">Your message has been sent. We will be in touch soon.</span>';
						$("#sf-fields").hide();
					} 
					else {
						result = '<span class="notification_error">Error submitting form.</span>';
						$("#sf-fields").hide();
					}
					$(this).html(result);
				});
			}
		});
		return false;

	});
});

$(window).load(function() {
	$('#photoContent').jScrollPane();
	$('#scrollableContent').jScrollPane();

	$.getScript("http://twitter.com/javascripts/blogger.js", function(){});
	$.getScript("http://twitter.com/statuses/user_timeline/Sirarigold.json?callback=twitterCallback2&count=2", function(){});
});
