// JavaScript Document

var currentLockupId  = '1';
var switchSpeed      = 9000;
var startSwitchDelay = 4000 + switchSpeed;
var animateSpeed     = 800;
var timeoutId        = 0;

var lockupHero1;
var lockupHero2;
var lockupHero3;

var glazesChannelDialogVideoInner;

$(function() {
	$('.lockup-selector span').click(function() {
		var index = this.id.lastIndexOf('-');
		var id    = this.id.substr(index + 1);
		
		switchLockup(id);
	});
	
	timeoutId = setTimeout("showNextLockup()", startSwitchDelay);
});

function showNextLockup()
{
	var id = parseInt(currentLockupId) + 1;
	if (id > 3) id = 1;
	
	switchLockup(id);
}

function switchLockup(id)
{
	if (currentLockupId == id) return;
	clearTimeout(timeoutId);
	
	fadeLockup(currentLockupId);
	showLockup(id);
	
	$('#selectlockup-' + id).removeClass('off');
	$('#selectlockup-' + currentLockupId).removeClass('on');
	
	$('#selectlockup-' + id).addClass('on');
	$('#selectlockup-' + currentLockupId).addClass('off');
	
	currentLockupId = '' + id;
	timeoutId = setTimeout("showNextLockup()", switchSpeed);
}

function fadeLockup(id)
{
	$('.lockup' + id).fadeOut(animateSpeed);
}

function showLockup(id)
{
	$('.lockup' + id).fadeIn(animateSpeed);
}

/* Loads Amazing Glazes Videos */

function enableLockup1()
{
	$('#home-hero-lockup1').click(function() {
		clearTimeout(timeoutId);
		loadHomeVideo("how-to-basics.f4v", "home-hero-lockup1", true);
		return false;
	});
}

function enableLockup2()
{
	$('#home-hero-lockup2').click(function() {
		clearTimeout(timeoutId);
		loadHomeVideo("easy-applications.f4v", "home-hero-lockup2", true);
		return false;
	});
}

function enableLockup3()
{
	$('#home-hero-lockup3').click(function() {
		clearTimeout(timeoutId);
		loadHomeVideo("inspired-designs.f4v", "home-hero-lockup3", true);
		return false;
	});
}

function loadHomeVideo(file, id, autoplay)
{
	var basepath = siteURL;
	var params   = {};
	params.menu  = "false";
	params.base  = basepath;
	params.allowFullScreen = "true";
	params.wmode = "opaque";
	
	var flashvars = {};
	flashvars.video_url = siteURL + "/content/videos/amazing-glazes/" + file;
	if (autoplay) flashvars.autoplay  = "true";
	
	swfobject.embedSWF(siteURL + "/swf/video-player/home-lockup.swf", id, "568", "344", "9.0.128", "", flashvars, params);
}

/* Glazes Channel Inline Module */

function showGlazesChannelDialog()
{
	var dialog = $('#dialog-glazes-channel-popup');

	if (isIE6())
	{
		centerAbsoluteElement(dialog);
		$(window).resize(function(){centerAbsoluteElement(dialog);});
		$(window).scroll(function(){centerAbsoluteElement(dialog);});
	}
	else
	{
		centerFixedElement(dialog);
		$(window).resize(function(){centerFixedElement(dialog);});
	}
	
	$('.dialog .button-close').unbind();
	$('.dialog .button-close').click(hideGlazesChannelDialog);
	
	dialog.show();
	showBlocker();
	
	$('div#blocker').unbind();
	$('div#blocker').click(hideGlazesChannelDialog);
}

function hideGlazesChannelDialog()
{
	// Stop Video from playing when dialog is closed
	$('#dialog-glazes-channel-popup .video').html(glazesChannelDialogVideoInner);
	
	hideBlocker();
}

