Fx.Morph = Fx.Styles.extend({
 
	start: function(className){
 
		var to = {};
 
		$each(document.styleSheets, function(style){
			var rules = style.rules || style.cssRules;
			$each(rules, function(rule){
				if (!rule.selectorText.test('\.' + className + '$')) return;
				Fx.CSS.Styles.each(function(style){
					if (!rule.style || !rule.style[style]) return;
					var ruleStyle = rule.style[style];
					to[style] = (style.test(/color/i) && ruleStyle.test(/^rgb/)) ? ruleStyle.rgbToHex() : ruleStyle;
				});
			});
		});
		return this.parent(to);
	}
 
});
 
Fx.CSS.Styles = ["backgroundColor", "backgroundPosition", "color", "width", "height", "left", "top", "bottom", "right", "fontSize", "letterSpacing", "lineHeight", "textIndent", "opacity"];
 
Fx.CSS.Styles.extend(Element.Styles.padding);
Fx.CSS.Styles.extend(Element.Styles.margin);
 
Element.Styles.border.each(function(border){
	['Width', 'Color'].each(function(property){
		Fx.CSS.Styles.push(border + property);
	});
});

var scroll;
var scrollHeader;
var activeLocation;

GB_myShow = function(caption, url, /* optional */ height, width, callback_fn) {
    var options = {
        caption: caption,
        height: height || 500,
        width: width || 500,
        fullscreen: false,
        show_loading: false,
		center_win:true,
        callback_fn: callback_fn
    }
    var win = new GB_MyWindow(options);
    return win.show(url);
}


window.addEvent('load', function() {
	var myMorph2 = new Fx.Morph("header", {wait: false,duration:800, onComplete:function(){
		
		scrollHeader.toElement('cWebsiteLocation');
		var qs = new Querystring()
		if (qs.get("ShowBox")=="Lottery")
		{
			playMusic=false;

			//if ()
			setTimeout("GB_myShow('Free Business Card or Logo', '/SignupForms/freebusinesscardorlogo.html', 380, 750);", 1500)
			//window.location="http://meancanary.com";
		}
		else
		{
		setTimeout("playMusic();", 1500);	
		}
	}
	});
	
	$("header").setStyle('display', 'block');
	$("header").setStyle('filter', 'alpha(opacity=1)');
	$("header").setStyle('-moz-opacity', '.01');
	$("header").setStyle('opacity', '.01');
	
	myMorph2.start('demo-bar-show');


});

function playMusic()
{


}

var volset=false;
function phaseDownVolume(volume)
{
	if (volset==false && volume>0){
	soundManager.setVolume('music', volume);
	volume-=1;
	setTimeout("phaseDownVolume(" + volume + ");", 3000);
	}
}

var currentVolume=20;

function volUp()
{
	volset=true;
	if (currentVolume>=100)
	{
		soundManager.setVolume('music', 100);
		currentVolume=100;
	}
	else
	{
		soundManager.setVolume('music', currentVolume + 5)
		currentVolume+=5;
	}
	
	if (currentMute)
	volMute();
}

function volDown()
{
	volset=true;
	if (currentVolume<=0)
	{
		soundManager.setVolume('music', 0);
		currentVolume=0;
	}
	else
	{
		soundManager.setVolume('music', currentVolume - 5)
		currentVolume-=5;
	}
	
	if (currentMute)
	volMute();
}

var currentMute=false;
function volMute()
{
	if (currentMute)
	{
		soundManager.setVolume('music', currentVolume);
		soundManager.setVolume('beep', 100);
		soundManager.setVolume('zap', 100);
		volButton.src="images/volumebutton.jpg";
		currentMute=false;
	}
	else
	{
		soundManager.setVolume('music', 0);
		soundManager.setVolume('beep', 0);
		soundManager.setVolume('zap', 0);
		
		currentMute=true;
		volButton.src="images/volumebutton2.jpg";
	}
	
}

var activeContent;
var animating;
var supress=false;
var pageLoaded=false;
	
window.addEvent('domready', function() {	
soundManagerInit();			 

isMac = (navigator.appVersion.indexOf("Mac")!=-1) ? true : false;
NS4 = (document.layers) ? true : false;
IEmac = ((document.all)&&(isMac)) ? true : false;
IE4plus = (document.all) ? true : false;
IE4 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 4.")!=-1)) ? true : false;
IE5 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 5.")!=-1)) ? true : false;
IE6 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 6.")!=-1)) ? true : false;
IE7 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 7.")!=-1)) ? true : false;
ver4 = (NS4 || IE4plus) ? true : false;
NS6 = (!document.layers) && (navigator.userAgent.indexOf('Netscape')!=-1)?true:false;

if (IE6||IE5)
document.getElementById("header").src="images/mclogogif.gif";
	
//	$("tablePageWrapper").setStyles("height:" + window.getSize().size.y);

	scrollHeader = new Fx.Scroll('demo-wrapper', { 
	wait: false,
	duration: 1000,
	offset: {'x': -200, 'y': -50},
	transition: Fx.Transitions.Quad.easeInOut,
	onComplete: function(){if(pageLoaded==false){
		
		var myMorph = new Fx.Morph("demo-bar", {wait: false,duration:800, onComplete:function(){}});
		
		$("demo-bar").setStyle('display', 'block');
		$("demo-bar").setStyle('filter', 'alpha(opacity=1)');
		$("demo-bar").setStyle('-moz-opacity', '.01');
		$("demo-bar").setStyle('opacity', '.01');
		
		myMorph.start('demo-bar-show');	
		;pageLoaded=true;}}
	});

	scroll = new Fx.Scroll('demo-wrapper', {
	wait: false,
	duration: 500,
	offset: {'x': -200, 'y': -50},
	transition: Fx.Transitions.Quad.easeIn
	});

	$('demo-wrapper').scrollTo($('home').getPosition().x, $('home').getPosition().y);
//	$('demo-bar').addEvent('mouseleave', function(event) {
//		event = new Event(event).stop();
		
//		if (activeLocation==null)
//		activeLocation='cWebsiteLocation'

//		scroll.toElement(activeLocation);
//		showContent(activeContent, event);
//	});
	 
	$('cWebsiteLocationLink').addEvent('mouseenter', function(event) {
		playSound(0);
	});

	$('cMarketingLocationLink').addEvent('mouseenter', function(event) {
		playSound(0);
	});
	
	$('cSolutionsLocationLink').addEvent('mouseenter', function(event) {
		playSound(0);
	});


$('btnCloseMarketing').addEvent('click', function(event){
	$('cMarketingLocationLink').fireEvent('click');
	$('cWebsiteLocationLink').fireEvent('mouseenter');
});

$('btnCloseWebsite').addEvent('click', function(event){
	$('cWebsiteLocationLink').fireEvent('click');
	$('cWebsiteLocationLink').fireEvent('mouseenter');
});

$('btnCloseSolutions').addEvent('click', function(event){
	$('cSolutionsLocationLink').fireEvent('click');
	$('cWebsiteLocationLink').fireEvent('mouseenter');
});

var allLinks=$$("a");
var buttonsToClose=allLinks.filterByClass('buttonCloseContent');

buttonsToClose.each(function(element){
	alert(element.id);
	element.addEvent("click", function(event){
		alert("test");
		event=new Event(event).stop();
		showContent('cHide', event);
	});
 });

	function showContent(contentId, e){
		if (animating)
		return false;
		
		var hideItFirst;
		
		if (activeContent!=null){
			if (contentId!=null){
				hideItFirst=true;
			}
			else{
			hideItFirst=true;
			}
		}
		else{
			hideItFirst=false;	
		}
		
		if (hideItFirst)
		{
			if (contentId!=null)
			{
				if (activeContent==contentId)
				return false;
			}
			
			var myMorphHide = new Fx.Morph(activeContent, {wait: false,duration:200, onStart:function(){
					animating=true;
					
					$(activeContent).setStyle('overflow', 'hidden');
					$(contentId).setStyle('overflow', 'hidden');

					//else
					//supress=true;
				},
				onComplete:function(){
					
					if (contentId!=null)
					{
						$(activeContent).setStyle('display','none');
						activeContent=contentId;
					
						var myMorph = new Fx.Morph(contentId, {wait: false,duration:400, onStart: function(){
					   		$(contentId).setStyle('display', 'block');
							$(contentId).setStyle('filter', 'alpha(opacity=1)');
							$(contentId).setStyle('-moz-opacity', '.01');
							$(contentId).setStyle('opacity', '.01');
							$(contentId).setStyle('overflow', 'hidden');
						},
						onComplete:function(){
							animating=false;	
							$(contentId).setStyle('overflow', 'auto');

						}});
												
						if (contentId!='cHide'){
						myMorph.start('contentTextShow');
						}
						else
						animating=false;
					}
					else
					{
						animating=false;	
					}
				}
			});
			
			if (contentId!=null)
			{
				$(contentId).setStyle('display', 'block');
				$(contentId).setStyle('filter', 'alpha(opacity=1)');
				$(contentId).setStyle('-moz-opacity', '.01');
				$(contentId).setStyle('opacity', '.01');
				//$(contentId).setStyle('overflow', 'auto');
			}
			
			
			//new Event(e).stop();
			myMorphHide.start('contentTextHide');
		}
		else
		{	
			if (contentId!=null)
			activeContent=contentId;
			
			if (contentId!=null)
			{
				$(contentId).setStyle('display', 'block');
				$(contentId).setStyle('filter', 'alpha(opacity=1)');
				$(contentId).setStyle('-moz-opacity', '.01');
				$(contentId).setStyle('opacity', '.01');
				$(contentId).setStyle('overflow', 'auto');
				var myMorph = new Fx.Morph(contentId, {wait: false,duration:400, onStart:function(){
					animating=true;
					$(activeContent).setStyle('overflow', 'hidden');
					$(contentId).setStyle('overflow', 'hidden');
				}, onComplete:function(){
					animating=false;
					$(activeContent).setStyle('overflow', 'auto');
					$(contentId).setStyle('overflow', 'auto');
				}});
			
			//new Event(e).stop(); 
			
			if (contentId!='cHide')
			myMorph.start('contentTextShow');
			}
		}
	}
	
	$('cWebsiteLocationLink').addEvent('click', function(event) {
		if (animating)
		return false;
		
		event = new Event(event).stop();


		if (activeContent=='cWebsite'){
			showContent('cHide');
			var fx = new Fx.Styles($('cWebsiteLocationLink'), {duration:500, wait:false});
			fx.start({
				color: '#ffffff'
			});
			activeLocation='cWebsiteLocation';
			return false;
		}

		if (activeContent==null)
		{
			duration=0;	
		}
		else
		{
			duration=750;	
		}

		scroll2 = new Fx.Scroll('demo-wrapper', {
		wait: false,
		duration: duration,
		offset: {'x': -200, 'y': -50},
		transition: Fx.Transitions.Quad.easeOut,
		onComplete: function(){
			showContent('cWebsite', event);
			playSound(1);
						
			var fx = new Fx.Styles($('cWebsiteLocationLink'), {duration:500, wait:false});
			fx.start({
				color: '#ff0000'
			});

			activeLocation='cWebsiteLocation';			
		}
		
		});

		if (activeLocation!=null){
			var fx = new Fx.Styles($(activeLocation + 'Link'), {duration:500, wait:false});
			fx.start({
				color: '#ffffff'
			});
		}
		showContent('cHide');
		scroll2.toElement('cWebsiteLocation');
	});
	
	$('cMarketingLocationLink').addEvent('click', function(event) {
		if (animating)
		return false;
		
		event = new Event(event).stop();
		
		if (activeContent=='cMarketing'){
			showContent('cHide');
			activeLocation='cWebsiteLocation';
			
			var fx = new Fx.Styles($('cMarketingLocationLink'), {duration:500, wait:false});
			fx.start({
				color: '#ffffff'
			});
			return false;
		}
			
		scroll2 = new Fx.Scroll('demo-wrapper', {
		wait: false,
		duration: 750,
		offset: {'x': -200, 'y': -50},
		transition: Fx.Transitions.Quad.easeOut,
		onComplete: function(){
			
			showContent('cMarketing', event);
			playSound(1);
			
			var fx = new Fx.Styles($('cMarketingLocationLink'), {duration:500, wait:false});
			fx.start({
				color: '#ff0000'
			});

			activeLocation='cMarketingLocation';		
		}
		
		});
		
		if (activeLocation!=null){
			var fx = new Fx.Styles($(activeLocation + 'Link'), {duration:500, wait:false});
			fx.start({
				color: '#ffffff'
			});
		}
		showContent('cHide');
		scroll2.toElement('cMarketingLocation');
		
	});
	
	$('cSolutionsLocationLink').addEvent('click', function(event) {
		if (animating)
		return false;
		
		event = new Event(event).stop();
		
		if (activeContent=='cSolutions'){
			showContent('cHide');
			activeLocation='cWebsiteLocation';
			
			var fx = new Fx.Styles($('cSolutionsLocationLink'), {duration:500, wait:false});
			fx.start({
				color: '#ffffff'
			});
			
			return false;
		}
			
		scroll2 = new Fx.Scroll('demo-wrapper', {
		wait: false,
		duration: 750,
		offset: {'x': -200, 'y': -50},
		transition: Fx.Transitions.Quad.easeOut,
		onComplete: function(){
			showContent('cSolutions', event);
			playSound(1);
			
			var fx = new Fx.Styles($('cSolutionsLocationLink'), {duration:500, wait:false});
			fx.start({
				color: '#ff0000'
			});
			activeLocation='cSolutionsLocation';
		}
		});
		
		if (activeLocation!=null){
			var fx = new Fx.Styles($(activeLocation + 'Link'), {duration:500, wait:false});
			fx.start({
				color: '#ffffff'
			});
		}
		showContent('cHide');
		scroll2.toElement('cSolutionsLocation');
	});
		
});


