var myFx;
var lastPopupWindow = '';

var myRotator = null;
var imgRotationState = 0;
var imgRotationPeriod = 4000; //ms
var myImgs = new Array();
myImgs[0] = 'images/samplesaint_b2b_compslice.jpg';
myImgs[1] = 'images/samplesaint_b2b_comp2slice.jpg';
myImgs[2] = 'images/samplesaint_b2b_comp3slice.jpg';

var quoteRotator = null;
var quoteRotationState = 0;
var quoteRotationPeriod = 7000; //ms
var myQuotes = new Array();
myQuotes[0] = '"This is a hip way to save money." - Candace H.';  //Hodnett
myQuotes[1] = '"I would love to get rid of the paper in my purse." - Lori B.'; //Boerger
myQuotes[2] = '"This is so cool.  This is great.  I would love to put coupons on my cell phone." - Alice D.'; //Davis
myQuotes[3] = '"I am glad this is finally here!" - Cameron B.'; //Beahm
myQuotes[4] = '"This is a great idea.  Coupons on your cell phone.  Wow!" - Doreen S.'; //Samaniego

function startQuoteRotation()
{
	rotateQuote();
	quoteRotator = rotateQuote.periodical(quoteRotationPeriod, quoteRotator);
}

function rotateQuote()
{
	$('testimonialDiv').setText(myQuotes[quoteRotationState]);	
	quoteRotationState+= 1;
	if(quoteRotationState==myQuotes.length)
		quoteRotationState = 0;
}

function startHomepageRotation()
{
	var imgRotator = $('imgHomepageRotation');
	myRotator = rotateHomepage.periodical(4000, myRotator);
	imgRotator.addEvent('click', toggleHomepageRotation);
}

function rotateHomepage()
{
	$('imgHomepageRotation').src = myImgs[imgRotationState];	
	//this.src = myImgs[imgRotationState];	
	imgRotationState += 1;
	if(imgRotationState==myImgs.length)
		imgRotationState = 0;
}

function toggleHomepageRotation()
{
	if(myRotator!=null)
		myRotator = $clear(myRotator);
	else
		startHomepageRotation();
}

function toggleBlogEntry(id)
{
	myFx = new Fx.Style(id, 'height').set(20);
}

function clearRegistrationFields()
{
	$('txtFullName').value = '';
	$('slctTitle').selectedIndex = 0;
	$('txtCompany').value = '';
	$('txtEmail').value = '';
	$('txtPhone').value = '';
	$('slctIndustry').selectedIndex = 0;
	$('txtPostalCode').value = '';
	$('slctCountry').selectedIndex = 0;
	$('txtHearAboutUs').value = '';
	$('txtAddComments').value = '';
}

function checkRegistrationFields()
{
//alert($('txtFullName').value);
//alert($('slctTitle').options[$('slctTitle').selectedIndex].text);
	if($('txtFullName').value=='')
		return false;
	if($('slctTitle').selectedIndex==0)
		return false;
	if($('txtCompany').value=='')
		return false;
	if($('txtEmail').value=='')
		return false;
	if($('txtPhone').value=='')
		return false;
	if($('slctIndustry').selectedIndex==0)
		return false;
	if($('txtPostalCode').value=='')
		return false;
	if($('slctCountry').selectedIndex==0)
		return false;
	return true;
}

function registrationComplete(txt)
{
	if(txt=='success')
	{
		alert('Registration successful!');
		clearRegistrationFields();
		hideServiceWindow('registrationWindow');
	}
	else
	{
		alert('Registration failed: ');
	}
}

function registerUser()
{
	if(checkRegistrationFields())
	{
		objAJAX = new Ajax('umbraco/XMLRegister.aspx?fn='+$('txtFullName').value+'&ti='+$('slctTitle').options[$('slctTitle').selectedIndex].text+'&co='+$('txtCompany').value+'&em='+$('txtEmail').value+'&ph='+$('txtPhone').value+'&in='+$('slctIndustry').options[$('slctIndustry').selectedIndex].text+'&pc='+$('txtPostalCode').value+'&cn='+$('slctCountry').options[$('slctCountry').selectedIndex].text+'&au='+$('txtHearAboutUs').value+'&ac='+$('txtAddComments').value, {
			method: 'get'
		});
		objAJAX.addEvent('onComplete', registrationComplete);
    		objAJAX.request();
	}
	else
		alert('Please complete all required fields.');
}

//registrationWindow showRegistration

function showServiceWindow(id)
{
	var myFx = new Fx.Style('overlayBackground', 'height').set(window.getScrollHeight());
	document.getElementById('overlayBackground').style.display='block';
	myFx = new Fx.Style('overlayBackground', 'opacity').set(0.8);

	//Hide other window that's showing
	if(lastPopupWindow!='')
		hideServiceWindow(lastPopupWindow);
	
	document.getElementById(id).style.display='block';
	document.getElementById(id).style.visibility = 'hidden';

	//Set window width
	if(id!='retailExperience'&&id!='consumerExperienceM'&&id!='consumerExperienceD'&&id!='redemptionExperience'&&id!='demoPopUpWindow')
		myFx = new Fx.Style(id, 'width').set(465);
	else
	{
		if(id!='demoPopUpWindow')
			myFx = new Fx.Style(id, 'width').set(950);
		$(id).setStyle('text-align', 'center');
	}

	//Position popup window
	if(id=='demoPopUpWindow'||id=='registrationWindow')
	{
		myFx = new Fx.Style(id, 'top').set(window.getScrollTop() + 175);
		myFx = new Fx.Style(id, 'left').set((window.getScrollWidth()-$(id).getStyle('width').toInt()) / 2);
	}
	else
	{
		myFx = new Fx.Style(id, 'top').set(window.getScrollTop() + 200);
		myFx = new Fx.Style(id, 'left').set(7 + $('middleContent').getLeft() + ( ($('middleContent').getCoordinates().width - $(id).getCoordinates().width) / 2) );
	}

	myFx = new Fx.Style(id, 'opacity', {duration:500}).start(0, 1.0);
	lastPopupWindow = id;
}

function hideServiceWindow(id)
{
	document.getElementById(id).style.visibility='hidden';
	document.getElementById(id).style.display='none';
	var myFx = new Fx.Style(id, 'opacity').set(0);
	lastPopupWindow = '';

	document.getElementById('overlayBackground').style.display='none';
	myFx = new Fx.Style('overlayBackground', 'opacity').set(0);
}

function hidePopUpWindow(id)
{
    //var myFx = new Fx.Style('overlayBackground', 'display').set('none');
    //document.getElementById('overlayBackground').style.display='none';
    //myFx = new Fx.Style('overlayBackground', 'opacity').set(0);
    document.getElementById(id).style.display='none';
    myFx = new Fx.Style(id, 'opacity').set(0);
    //swfobject.getObjectById('demoPopUpVideo').StopPlay();
    document.getElementById('demoPopUpVideo').StopPlay();
    //removeFlashVideo('demoPopUpVideo','demoPopUpVideoPlaceHolder','demoPopUpVideoContainer');
}

function showPopUpWindow(id) {
    //Audit demo video
    //auditDemoVideo()

     var POPUP_WINDOW_OPACTIY = 1.0;
     var POPUP_BACKGROUND_OPACTIY = 0.35;
     var POPUP_WINDOW_HEIGHT = 103;
    
    //Display, size and set opacity of overlay background
    //var myFx = new Fx.Style('overlayBackground', 'height').set(window.getScrollHeight());
    //document.getElementById('overlayBackground').style.display='block';
    //myFx = new Fx.Style('overlayBackground', 'opacity').set(POPUP_BACKGROUND_OPACTIY);
    
    //Position popup window
    myFx = new Fx.Style(id, 'top').set(window.getScrollTop() + POPUP_WINDOW_HEIGHT);
    myFx = new Fx.Style(id, 'left').set((window.getScrollWidth()-$(id).getStyle('width').toInt()) / 2);
    
    //Set pop up window visibility and opacity
    document.getElementById(id).style.display='block';
    myFx = new Fx.Style(id, 'opacity').set(POPUP_WINDOW_OPACTIY);
    
    //Make window visible
    document.getElementById(id).style.display='block'; 
    document.getElementById('demoPopUpContainer').style.display='block';
    //$(id).setOpacity(POPUP_WINDOW_OPACTIY);
    //$('demoPopUpContainer').setOpacity(POPUP_WINDOW_OPACTIY);
    /*myFx = new Fx.Style('demoPopUpWindowLeftBar', 'opacity').set(POPUP_WINDOW_OPACTIY);
    //myFx = new Fx.Style('demoPopUpWindowRightBar', 'opacity').set(POPUP_WINDOW_OPACTIY);
    //myFx = new Fx.Style('demoPopUpWindowWideTopBar', 'opacity').set(POPUP_WINDOW_OPACTIY);
    //myFx = new Fx.Style('demoPopUpWindowWideBottomBar', 'opacity').set(POPUP_WINDOW_OPACTIY);*/

    //Insert demo video
/*    if(POPUP_WINDOW_OPACTIY==1.0) {
        myFx = new Fx.Style('demoPopUpVideoContainer', 'border-style:').set('solid');
        myFx = new Fx.Style('demoPopUpVideoContainer', 'border-color:').set('#92AFDB');
        myFx = new Fx.Style('demoPopUpVideoContainer', 'border-width:').set('1px');
    }
    myFx = new Fx.Style('demoPopUpVideoContainer', 'opacity').set(1);*/
    
    //Adjust height of side bars
    /*myFx = new Fx.Style('demoPopUpWindowLeftBar', 'width').set(5); //$('demoPopUpContainer').clientHeight
    myFx = new Fx.Style('demoPopUpWindowRightBar', 'width').set(5);
    myFx = new Fx.Style('demoPopUpWindowLeftBar', 'height').set($('demoPopUpContainer').clientHeight); //$('demoPopUpContainer').clientHeight
    myFx = new Fx.Style('demoPopUpWindowRightBar', 'height').set($('demoPopUpContainer').clientHeight);*/
//alert($('demoPopUpContainer').clientHeight);
}

function insertFlashVideo(target, videoid, src, height, width)
{
    //Add swf with AC_FL
    if (AC_FL_RunContent == 0) {
        alert("This page requires AC_RunActiveContent.js.");
    } else {
    AC_FL_RunContent(
        'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
        'width', width,
        'height', height,
        'src', 'videoplayer.prt2-edit2.swf',
        'quality', 'high',
        'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
        'align', 'middle',
        'play', 'true',
        'loop', 'true',
        'scale', 'showall',
        'wmode', 'window',
        'devicefont', 'false',
        'id', videoid,
        'bgcolor', '#ffffff',
        'name', videoid,
        'menu', 'true',
        'allowFullScreen', 'true',
        'allowScriptAccess','sameDomain',
        'movie', 'videoplayer.prt2-edit2',
        'salign', ''
        ); //end AC code
    }
    
    /* 
    //Add swf with SWFobject
    var params = {};
    //params.codebase = "http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0";
    params.width = width;
    params.height = height;
    params.quality = "high";
    params.align = "middle";
    params.play = "true";
    params.loop = "true";
    params.scale = "showall";
    params.wmode = "window";
    params.devicefont = "false";
    params.id = videoid;
    params.bgcolor = "#ffffff";
    params.name = videoid;
    params.menu = "true";
    params.allowFullScreen = "true";
    params.allowScriptAccess = "sameDomain";
    //params.movie = "videoplayer.prt2-edit2";
    params.salign = "";
    params.menu = "false";

    var attributes = {};
    attributes.id = videoid;
    attributes.name = videoid;

    swfobject.embedSWF(src, target, width, height, "9.0.0", "expressInstall.swf", {}, params, attributes);
    */
}

function removeFlashVideo(videoid, placeholderid, videocontainerid)
{
    //    removeFlashVideo('demoPopUpVideo','demoPopUpVideoPlaceHolder','demoPopUpVideoContainer');
    swfobject.removeSWF(videoid);
    //var el = new Element ('div',{'id':placeholderid});
    //$(videocontainerid).injectTop(el);
}