function loadMenu() {
	var so = new SWFObject("flash/menu.swf","menuswf","550","90","6","#000000");
	so.addParam("wmode","transparent");
	$('menu').setStyle('margin-top', '-50px');
	so.write("menu");
}

function loadMusic() {
	var so = new SWFObject("flash/xspf/xspf_player_slim.swf?playlist_url=flash/xspf/playlist.xspf&autoplay=true","menuswf","243","15","6","#000000");
	so.addParam("wmode","transparent");
	so.write("music");	
}


function playMenu() {
	if (pageLoaded != 1){
		$('menuswf').Play();
	
		pageLoaded = 1;
	}
}

function loadPage() {
	resetContent();
	if (!window.ie6 || activexenabled()) {
		$('main').effect('margin-top', {duration: 1000}).start(105);
		$('center').effect('height', {duration: 1000}).start(0, 400).chain(function() {
			if (window.ie6){
				$('logo').setStyles('filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src="images/swlogo3.png"); background: none;');
			} else {
				$('logo').effect('opacity', {duration: 800}).start(1);
			}
			$('top').effect('opacity', {duration: 800}).start(.2);
			$('bottom').effect('opacity', {duration: 800}).start(.2).chain(function() {
				$('menu').effect('right', {duration: 1000}).start(50).chain(function() {
					var html = "<div id=content></div>";
					$('center').setHTML(html);
					pickPage();
					$('center').setStyles('height: 400px; line-height: normal; font-size: 1em; color: white;');
				});
			});
		});
	} else {
		
		html = "This is an interactive page and requires Internet Explorer to have ActiveX enabled.";
		html = html + "<br>";
		html = html + "For help on Howto Enable ActiveX, click <a href=\"http://www.pcsurveillance.net/support/index.php?article=1006\">here</a>.";
		
		new Element('div', {
			'class': 'alert'}).setHTML(html).injectBefore('logo');
	}
}

function pickPage() {
	var hash = window.location.hash.split('#');
	hash.shift();
	
	switch(hash[0])
	{
		case 'about':
			playMenu();
			loadAbout();
			break;
		case 'calendar':
			playMenu();
			loadCal();
			break;
		case 'faq':
			playMenu();
			loadFAQ();
			break;
		case 'vendors':
			playMenu();
			loadVendors();
			break;
		case 'albums':
			playMenu();
			loadAlbums();
			break;
		case 'prices':
			playMenu();
			loadPrices();
			break;
		case 'proposals':
			playMenu();
			loadProposal();
			break;
		case 'contact':
			playMenu();
			loadContact();
			break;
		case 'flipbook':
			playMenu();
			loadFlipbook(hash[1], hash[2]);
			break;
		case 'galleries':
			playMenu();
			loadGalleries(hash[1], hash[2]);
			break;
		default:
			loadHome();
			break;
	}
}

function loadHome() {
	if (!currentPage.match(/home/)) {
	resetContent();
	$('content').setStyle('text-align', 'center');
		if (lowres == 1) {
			var so = new SWFObject("flash/studioworks2.swf","contentswf","570","265","6","#000000");
		} else {	
			var so = new SWFObject("flash/studioworks2.swf","contentswf","570","365","6","#000000");
		}
	so.addParam("wmode","transparent");
	so.write("content");
	
	currentPage = '#home';
	window.location.hash = '';
	}
}

function loadAbout() {
	resetContent();

	new Ajax('asp/about.asp', {
		method: "get",
		update: $("content")}).request();
	currentPage = window.location.hash = '#about';
}

function loadCal() {
	resetContent();

	new Ajax('asp/cal.html', {
		method: "get",
		update: $("content")}).request();
	currentPage = window.location.hash = '#calendar';
}


function loadFAQ() {
	resetContent();

	new Ajax('asp/faq.asp', {
		method: "get",
		update: $("content")}).request();
	currentPage = window.location.hash = '#faq';
}

function loadVendors() {
	resetContent();

	new Ajax('asp/vendors.asp', {
		method: "get",
		update: $("content")}).request();
	currentPage = window.location.hash = '#vendors';
}

function loadAlbums() {
	resetContent();

	new Ajax('asp/albums.asp', {
		method: "get",
		update: $("content")}).request();
	currentPage = window.location.hash = '#albums';
}

function loadPrices() {
	resetContent();

	new Ajax('asp/wedding_prices.asp', {
		method: "get",
		update: $("content"),
        onSuccess: function()
            {
                var u = 'info';
                var d = 'studioworkstx';
                var t = 'com';

                $("pricingEmail").href = "mailto:" + u + "@" + d + "." + t;
            }
        }).request();


	currentPage = window.location.hash = '#prices';
}

function loadProposal() {
	resetContent();
	
	$('content').setStyle('width', '960px');

	new Ajax('asp/propose.asp', {
		method: "get",
		update: $("content")}).request();
	currentPage = window.location.hash = '#proposals';
}


function loadLightbox(e) {
$('lightbox').effect('opacity').start(.7).chain(function() {
		e.effect('opacity').start(1);
	});
}

function loadContact() {
	resetContent();
	
	$('content').setStyles('padding: 0px;width: 960px;');
	
	var so = new SWFObject("flash/contactus.swf","contactflash","960","400","6","#000000");
	so.addParam("wmode","transparent");
	so.addParam("menu", "false");
	so.write("content");
	
	currentPage = window.location.hash = '#contact';
}

function loadFlipbook(book, width) {
	resetContent();
	
	$('content').setStyles('width: '+ width + 'px;');
	var so = new SWFObject("flipbooks/" + book + "-flipbook.swf","flipbookflash", width, "400","6","#000000");
	so.addParam("wmode","transparent");
	so.addParam("menu", "false");
	so.write("content");
	
	currentPage = window.location.hash = '#flipbook#'+book+'#'+width;
}


function loadGalleries(dir,subdir) {

    var get;
    var get2;

	$('thumb2').effect('left', {duration: 250}).start(0);
    
    if (subdir.match(/Seniors_Buzz_Clips/)){
        get = new Ajax('asp/buzz_thumbs.asp?dir='+dir+'/'+subdir, {
            method: "get",
            update: $("thumb2")});
    } else {
        get = new Ajax('asp/thumbs.asp?dir='+dir+'/'+subdir, {
            method: "get",
            update: $("thumb2")});
    }
        get2 = new Ajax('asp/gallery.asp?dir='+dir+'&subdir='+subdir, {
            method: "get",
            update: $("content")});

	if (window.ie) get.setHeader('If-Modified-Since', 'Sat, 1 Jan 1970 00:00:00 GMT');
	if (window.ie) get2.setHeader('If-Modified-Since', 'Sat, 1 Jan 1970 00:00:00 GMT');

	get.request().chain(function(){
		if ($('address').style.visibility != 'hidden'){
			//Fade the address out and drop the thumbnails
			$('address').effect('opacity').start(0).chain(function() {
				$E('div.thumb', 'main').setStyle('display', 'block');
				$('thumb').effect('opacity', {duration: 100}).start(1,1).chain(function() {
					$('thumb').effect('top').start(10).chain(function(){$('thumb').effect('top').start(0)});
				});
		});
	}
	get2.request().chain(function() {
        if (subdir.match(/Seniors_Buzz_Clips/)){
            window.location.href = $("1").href;
        } else {
	        document.body.style.backgroundImage = 'url(images/'+dir+'/'+dir+'Bkg.jpg)';
        } });

	});

	currentPage = window.location.hash = '#galleries#'+dir+'#'+subdir;
}

function moveThumbs(side) {
    if (side == 'left') {
        if ($("thumb2").getStyle('left') !== '0px' && $("thumb2").getStyle('left') !== 'auto' && $("thumb2").getStyle('left') !== '20px') {
	        $('thumb2').effect('opacity', {duration: 100, transition: Fx.Transitions.Quad.easeOut}).start(1, .75).chain(function() {
				curLeft = $('thumb2').getStyle('left').toInt();
				curLeft = (curLeft / 87).toInt() * 87;
				$('thumb2').effect('left', {duration: 300, transition: Fx.Transitions.Quad.easeOut}).start(curLeft + 4*87).chain(function() {
					$('thumb2').effect('opacity', {duration: 100, transition: Fx.Transitions.Quad.easeOut}).start(.75, 1);
					if ($('thumb2').getStyle('left').toInt() > 0) $('thumb2').effect('left', {duration: 100}).start(0);});
				});
        }
    }
    if (side == 'right') {
		if ($("thumb2").getStyle('left').toInt() - (5*87) > 0-($ES('li','thumb2').length *87) || $("thumb").getStyle('left') == 'auto'){
			$('thumb2').effect('opacity', {duration: 100, transition: Fx.Transitions.Quad.easeOut}).start(.75).chain(function() {
				if ($("thumb2").getStyle('left') == 'auto') {
				curLeft = 0;
				} else {
					curLeft = $('thumb2').getStyle('left').toInt();
				}
				if (window.opera && curLeft == 20) curLeft -= 20;
				curLeft = (curLeft / 87).toInt() * 87;
				$('thumb2').effect('left', {duration: 300, transition: Fx.Transitions.Quad.easeOut}).start(curLeft, curLeft - 4*87).chain(function() {
					$('thumb2').effect('opacity', {duration: 100, transition: Fx.Transitions.Quad.easeOut}).start(1);
				});
			});
        }
    }
}

function underConstruction() {
	alert("Under Construction!");
}

function comingSoon() {
	alert("Coming Soon!");
}

function loadImage(dir,file,e) {
	if (e == '' || e == null) {e = $('gallery_image');};
	var newImage = 'url(images/'+dir+'/'+file+')';
	e.setStyle('background-image', newImage);
}

function loadClip(dir,file) {
    get = new Ajax("images/"+dir+"/"+file, {
        method: "get",
        update: $("gallery_image") });

    get.request();
}

function resetContent() {
	document.body.style.backgroundImage = 'url(\'images/MainBkg.jpg\')';
	if (currentPage.match(/galleries/)){
		$('thumb').effect('top').start(10).chain(function(){
			$('thumb').effect('top').start(-100).chain(function() {
				$E('div.thumb', 'main').setStyle('display', 'none');
				$('thumb').effect('opacity').start(1,1).chain(function() {
					$('address').effect('opacity').start(1);
				});
			});
		});
	}

	if (currentPage !== 'blank'){
		$('content').empty();
		$('content').setStyles('padding-top: 10px; width: 760px; text-align: left;');
	}
}


function toggleHidden(el)
{
	if (el.getStyle('display') == 'none')
	{
		el.setStyle('display', 'block');
	}
	else
	{
		el.setStyle('display', 'none');
	}
}

function toggleAll(how)
{
	if (how == 'expand')
	{
		$ES('span', 'weddings_faq').setStyle('display', 'block');
		$ES('span', 'portraits_faq').setStyle('display', 'block');
		
	}
	else if (how == 'contract')
	{
		$ES('span', 'weddings_faq').setStyle('display', 'none');
		$ES('span', 'portraits_faq').setStyle('display', 'none');
		
	}
}

function sendContact(name,phone,email,comments,subscribe) {
	post = Object.toQueryString({
		Name: name,
		Phone: phone,
		Email: email,
		Comments: comments,
		Subscribe: subscribe});
	
	new Ajax('asp/sendContact.asp', {
		method: 'post',
		postBody: post,
		onComplete: function(request) {
			$('contactflash').Play();
		}
	}).request();
}
function closeBox(e) {
	e.effect('opacity').start(0).chain( function() {
		$('lightbox').effect('opacity').start(0);
	});
}

function showFlushed() {
	if ($('flushed').getStyle('display') == 'none') {
		$('matted').effect('opacity').start(1,0).chain(function() {
			$('matted').setStyle('display', 'none');
			$('flushed').setStyle('display', 'block');
			$('flushed').effect('opacity').start(0,1);
		});
	}
}

function showMatted() {
	if ($('matted').getStyle('display') == 'none') {
		$('flushed').effect('opacity').start(1,0).chain(function() {
			$('flushed').setStyle('display', 'none');
			$('matted').setStyle('display', 'block');
			$('matted').effect('opacity').start(0,1);
		});
	}
}
