var loc = document.location;
var theTitle = document.title;

function doAnchorCheck(){

	//fixes the title in IE7
	window.onload = function(){
		document.title = theTitle;
	}

	if(location.href.indexOf('/games_activities/') != -1){
		var anchor = location.href.split("#");
		if(anchor[1]){
			anchor = parseInt(anchor[1]);
			openContent(anchor);
		}
	}
}

function openContent(anchor){
	var gif = "gif"+anchor;
	var item = "item"+anchor;

	showHideContent(gif,item);
}

function writeGlobalNav() {
	flashObj = new FlashObj(
		'/DisneyChannel/playhouse/media/global/globalnav/nav2.swf', // swf
		'994', // width
		'157', // height
		'#7F70F3', // background
		'', // version
		'frameright', // id
		'xml=/DisneyChannel/playhouse/media/global/globalnav/config/global.xml&amp;property=celebration_center', // flashVars
		true, // optional argument false = "no autoplay". true or blank = "autoplay"
		'', // base target
		'exactfit' //scale
		)
	flashObj.render(true,"transparent");
}

function writeLogo() {
	flashObj = new FlashObj(
		'/DisneyChannel/playhouse/grownups/media/celebrationcenter/flash/logo.swf', // swf
		'146', // width
		'165', // height
		'#FFFFFF', // background
		'', // version
		'logoSwf', // id
		'homeLink=/DisneyChannel/playhouse/grownups/celebrationcenter/index.html', // flashVars
		true, // optional argument false = "no autoplay". true or blank = "autoplay"
		'', // base target
		'' //scale
		)
	flashObj.render(true,"transparent");
}

function writeMenu(config,which) {
	flashObj2 = new FlashObj(
		'/DisneyChannel/playhouse/grownups/media/celebrationcenter/flash/menu.swf', // swf
		'137', // width
		'200', // height
		'#FFFFFF', // background
		'', // version
		'menuSwf', // id
		'xmlConfig='+config+'&highlighted='+which, // flashVars
		true, // optional argument false = "no autoplay". true or blank = "autoplay"
		'', // base target
		'' //scale
		)
	flashObj2.render();
}
function writeMenuHariRaya(config,which) {
	flashObj2 = new FlashObj(
		'/DisneyChannel/playhouse/grownups/media/celebrationcenter/flash/menuHariRaya.swf', // swf
		'137', // width
		'200', // height
		'#FFFFFF', // background
		'', // version
		'menuSwf', // id
		'xmlConfig='+config+'&highlighted='+which, // flashVars
		true, // optional argument false = "no autoplay". true or blank = "autoplay"
		'', // base target
		'' //scale
		)
	flashObj2.render();
}

function writeDecorations(which) {
	flashObj = new FlashObj(
		'/DisneyChannel/playhouse/grownups/media/celebrationcenter/flash/decorations.swf', // swf
		'400', // width
		'150', // height
		'#FFFFFF', // background
		'', // version
		'decorationsSwf', // id
		'group='+which, // flashVars
		true, // optional argument false = "no autoplay". true or blank = "autoplay"
		'', // base target
		'' //scale
		)
	flashObj.render(true,"transparent");
}

function writePresentedBy() {
	//document.write('<img src="http://atv.disney.go.com/playhouse/grown-ups/media/celebrationcenter/images/global/presentedby.jpg" alt="Presented By" /><br />'
	//+'<img src="http://atv.disney.go.com/playhouse/grown-ups/media/celebrationcenter/images/global/vsmile.jpg" alt="V. Smile Baby" /><br />');
}

function writeThemes(highlighted,width,height) {
	if(width!=null){
		theWidth=width;
	}else{
		theWidth=172;
	}

	if(height!=null){
		theHeight=height;
	}else{
		theHeight=424;
	}

	flashObj = new FlashObj(
		'/DisneyChannel/playhouse/grownups/media/celebrationcenter/flash/themes.swf', // swf
		theWidth, // width
		theHeight, // height
		'#FFFFFF', // background
		'', // version
		'themesSwf', // id
		'xmlConfig=/DisneyChannel/playhouse/grownups/celebrationcenter/global/themes/config.xml&amp;highlighted='+highlighted, // flashVars
		true, // optional argument false = "no autoplay". true or blank = "autoplay"
		'', // base target
		'' //scale
		)
	flashObj.render();
}

function categorySelected(){
	var value = document.getElementById('categorySelect').options[document.getElementById('categorySelect').selectedIndex].value;
	if(value != null && value != ""){
		loc.href=value;
	}
}

function writeCategories(_selected,_checklistURL){
	document.write('<select id="categorySelect" onchange="categorySelected()">'
		+'<option value="">Choose a Category</option>'
		+'<option value="">Checklist</option>'
		+'<option value="/DisneyChannel/playhouse/grownups/celebrationcenter/invitations/index.html">Invitations</option>'
		+'<option value="/DisneyChannel/playhouse/grownups/celebrationcenter/giftwrap/index.html">Gift Wrap</option>'
		+'<option value="/DisneyChannel/playhouse/grownups/celebrationcenter/recipes/index.html">Recipes</option>'
		+'<option value="/DisneyChannel/playhouse/grownups/celebrationcenter/decorations/index.html">Decorations</option>'
		+'<option value="/DisneyChannel/playhouse/grownups/celebrationcenter/games_activities/index.html">Games &amp; Activities</option>'
		+'<option value="/DisneyChannel/playhouse/grownups/celebrationcenter/partyfavors/index.html">Party Favors</option>'
		+'<option value="/DisneyChannel/playhouse/grownups/celebrationcenter/thankyou_notes/index.html">Thank-You Notes</option>'
		
	+'</select>');
	
	var x=document.getElementById("categorySelect");
	var checklistIndex;
	
	if(_selected!=null && _selected!=""){
		x.selectedIndex=_selected;
	}
	
	for (i=0;i<x.length;i++){
		if(x.options[i].text.toLowerCase() == "checklist"){
			checklistIndex = i;
		}
	}
	
	if(_checklistURL!=null && _checklistURL!=""){
		x.options[checklistIndex].value = _checklistURL;
	}
	else{
		x.remove(checklistIndex);
	}
}
function writeCategoriesLunar(_selected,_checklistURL){
	document.write('<select id="categorySelect" onchange="categorySelected()">'
		+'<option value="">Choose a Category</option>'
		+'<option value="">Checklist</option>'
		+'<option value="/DisneyChannel/playhouse/grownups/celebrationcenter/recipes/lunarnewyear/index.html">Recipes</option>'
		+'<option value="/DisneyChannel/playhouse/grownups/celebrationcenter/decorations/lunarnewyear/index.html">Decorations</option>'
		+'<option value="/DisneyChannel/playhouse/grownups/celebrationcenter/games_activities/lunarnewyear/index.html">Games &amp; Activities</option>'
	+'</select>');
	
	var x=document.getElementById("categorySelect");
	var checklistIndex;
	
	if(_selected!=null && _selected!=""){
		x.selectedIndex=_selected;
	}
	
	for (i=0;i<x.length;i++){
		if(x.options[i].text.toLowerCase() == "checklist"){
			checklistIndex = i;
		}
	}
	
	if(_checklistURL!=null && _checklistURL!=""){
		x.options[checklistIndex].value = _checklistURL;
	}
	else{
		x.remove(checklistIndex);
	}
}
function writeCelebrationTip(which){
	document.write('<table id="tipText" cellpadding="0" cellspacing="0" border="0"><tr><td height="47"></td><tr><td width="8"></td><td>');
    
	if(which == "mmch"){
		document.write(''
		+'<img src="/DisneyChannel/playhouse/grownups/media/celebrationcenter/images/global/celebrationtip/mmch.jpg" alt="Celebration Tip" />'
		+'</td><td class="textStandard" align="left">'
		+'Bendy, swirly, squiggly straws in fun colors add a whimsical feel to any celebration.'
		+'');
	}
	else if(which == "specialagentoso"){
		document.write(''
		+'<img src="/DisneyChannel/playhouse/grownups/media/celebrationcenter/images/global/celebrationtip/specialagentoso.jpg" alt="Celebration Tip" />'
		+'</td><td class="textStandard" align="left">'
		+'A scooped out melon half makes a festive and easy bowl for fruit salad!'
		+'');
	}
	else if(which == "firstdayofschool"){
		document.write(''
		+'<img src="/DisneyChannel/playhouse/grownups/media/celebrationcenter/images/global/celebrationtip/firstdayofschool.jpg" alt="Celebration Tip" />'
		+'</td><td class="textStandard" align="left">'
		+'Milk is nourishing and comforting all at once. Make sure to have plenty of it on hand as the school year gets underway.'
		+'');
	}
	else if(which == "hispanicheritage"){
		document.write(''
		+'<img src="/DisneyChannel/playhouse/grownups/media/celebrationcenter/images/global/celebrationtip/hispanicheritage.jpg" alt="Celebration Tip" />'
		+'</td><td class="textStandard" align="left">'
		+'Using potted plants is an eco-friendly way to decorate a party, and once the event is over, they can live on as decor.'
		+'');
	}
	else if(which == "hispanicheritage_espanol"){
		document.write(''
		+'<img src="/DisneyChannel/playhouse/grownups/media/celebrationcenter/images/global/celebrationtip/hispanicheritage.jpg" alt="Punta de Celebraci&oacute;n" />'
		+'</td><td class="textStandard" align="left">'
		+'Usar plantas sembradas es una manera ecol&oacute;gica para decorar una fiesta, y una vez que termina el acontecimiento, pueden vivir como decoraci&oacute;n.'
		+'');
	}
	else if(which == "higglytownsummer"){
		document.write(''
		+'<img src="/DisneyChannel/playhouse/grownups/media/celebrationcenter/images/global/celebrationtip/higglytownsummer.jpg" alt="Celebration Tip" />'
		+'</td><td class="textStandard" align="left">'
		+'Colored mini-buckets can hold supplies at the party and then be sent home<br />with party guests filled<br />with goodies.'
		+'');
	}
	else if(which == "littleeinsteinssummer"){
		document.write(''
		+'<img src="/DisneyChannel/playhouse/grownups/media/celebrationcenter/images/global/celebrationtip/littleeinsteinssummer.jpg" alt="Celebration Tip" />'
		+'</td><td class="textStandard" align="left">'
		+'Encourage creativity with an icebreaker activity by inviting children to begin coloring on craft paper as soon as they arrive at the party.'
		+'');
	}
	else if(which == "littleeinsteinshalloween"){
		document.write(''
		+'<img src="/DisneyChannel/playhouse/grownups/media/celebrationcenter/images/global/celebrationtip/littleeinsteinshalloween.jpg" alt="Celebration Tip" />'
		+'</td><td class="textStandard" align="left">'
		+'Halloween typically means sugar overload for kids. You can keep it healthy and fun by giving out small, inexpensive toys instead during trick-or-treating. Parents will appreciate you for it.'
		+'');
	}
	else if(which == "imaginationmovers"){
		document.write(''
		+'<img src="/DisneyChannel/playhouse/grownups/media/celebrationcenter/images/global/celebrationtip/imaginationmovers.jpg" alt="Celebration Tip" />'
		+'</td><td class="textStandard" align="left">'
		+'Parties should never suffer from lack of color and texture. Using all kinds of festive napkins helps bring a party to life!'
		+'');
	}
	else if(which == "fathersday"){
		document.write(''
		+'<img src="/DisneyChannel/playhouse/grownups/media/celebrationcenter/images/global/celebrationtip/fathersday.jpg" alt="Celebration Tip" />'
		+'</td><td class="textStandard" align="left">'
		+'To keep little ones focused on crafts, try to be as prepared as possible by having all supplies on hand and ready to go!'
		+'');
	}
	else if(which == "johnnyspring"){
		document.write(''
		+'<img src="/DisneyChannel/playhouse/grownups/media/celebrationcenter/images/global/celebrationtip/johnnyspring.jpg" alt="Celebration Tip" />'
		+'</td><td class="textStandard" align="left">'
		+'Present party food more playfully by using cookie cutters to cut fruits, veggies, and sandwiches into fun shapes.'
		+'');
	}
	else if(which == "fourthofjuly"){
		document.write(''
		+'<img src="/DisneyChannel/playhouse/grownups/media/celebrationcenter/images/global/celebrationtip/fourthofjuly.jpg" alt="Celebration Tip" />'
		+'</td><td class="textStandard" align="left">'
		+'Decorate the party area<br />with American flags. It\'s appropriate for the occasion, and they can double as party favors!'
		+'');
	}
	else if(which == "mothersday"){
		document.write(''
		+'<img src="/DisneyChannel/playhouse/grownups/media/celebrationcenter/images/global/celebrationtip/mothersday.jpg" alt="Celebration Tip" />'
		+'</td><td class="textStandard" align="left">'
		+'Be sure to have lots of mom\'s favorite flowers around the house to help make her day fragrant and beautiful.'
		+'');
	}
	else if(which == "mmchhalloween"){
		document.write(''
		+'<img src="/DisneyChannel/playhouse/grownups/media/celebrationcenter/images/global/celebrationtip/mmchhalloween.jpg" alt="Celebration Tip" />'
		+'</td><td class="textStandard" align="left">'
		+'Decorate the party with mini-pumpkins and hay to create a fun and friendly atmosphere for all ages.'
		+'');
	}
	else if(which == "thanksgiving"){
		document.write(''
		+'<img src="/DisneyChannel/playhouse/grownups/media/celebrationcenter/images/global/celebrationtip/thanksgiving.jpg" alt="Celebration Tip" />'
		+'</td><td class="textStandard" align="left">'
		+'Cranberries symbolize everything tasty and colorful about Thanksgiving. Fill up a glass vase with the deep red berries and place seasonal flowers like mums inside for a festive decoration.'
		+'');
	}
	else if(which == "christmas"){
		document.write(''
		+'<img src="/DisneyChannel/playhouse/grownups/media/celebrationcenter/images/global/celebrationtip/christmas.jpg" alt="Celebration Tip" />'
		+'</td><td class="textStandard" align="left">'
		+'An inexpensive, small Christmas stocking makes a fun silverware holder for the table.'
		+'');
	}
	else if(which == "hanukkah"){
		document.write(''
		+'<img src="/DisneyChannel/playhouse/grownups/media/celebrationcenter/images/global/celebrationtip/hanukkah.jpg" alt="Celebration Tip" />'
		+'</td><td class="textStandard" align="left">'
		+'Wrap a few candles in a pretty blue ribbon to brighten your Hanukkah table, or give them as a gift to each guest.'
		+'');
	}
	else if(which == "kwanzaa"){
		document.write(''
		+'<img src="/DisneyChannel/playhouse/grownups/media/celebrationcenter/images/global/celebrationtip/kwanzaa.jpg" alt="Celebration Tip" />'
		+'</td><td class="textStandard" align="left">'
		+'Seasonal gourds are inexpensive, last a long time, and will brighten any Kwanzaa table.'
		+'');
	}
	else if(which == "newyear"){
		document.write(''
		+'<img src="/DisneyChannel/playhouse/grownups/media/celebrationcenter/images/global/celebrationtip/newyear.jpg" alt="Celebration Tip" />'
		+'</td><td class="textStandard" align="left">'
		+'Decorate the party area<br />with festive-colored balloons and ribbons to create a fun and friendly atmosphere for all ages.'
		+'');
	}
	else if(which == "valentinesday"){
		document.write(''
		+'<img src="/DisneyChannel/playhouse/grownups/media/celebrationcenter/images/global/celebrationtip/valentinesday.jpg" alt="Celebration Tip" />'
		+'</td><td class="textStandard" align="left">'
		+'Help party-goers identify their glasses with a variety of Valentine-themed ribbons.'
		+'');
	}
	else if(which == "teaparty"){
		document.write(''
		+'<img src="/DisneyChannel/playhouse/grownups/media/celebrationcenter/images/global/celebrationtip/teaparty.jpg" alt="Celebration Tip" />'
		+'</td><td class="textStandard" align="left">'
		+'A bright selection of mis-matched cups and saucers adds color and whimsy to the table.'
		+'');
	}
	else if(which == "hariraya"){
		document.write(''
		+'<img src="/DisneyChannel/playhouse/grownups/media/celebrationcenter/images/global/celebrationtip/hariraya.jpg" alt="Hari Raya Tip" />'
		+'</td><td class="textStandard" align="left">'
		+'Fold and create wonderful shapes using colored napkins to add more fun this Hari Raya.'
		+'');
	}
	else if(which == "lunarnewyear"){
		document.write(''
		+'<img src="/DisneyChannel/playhouse/grownups/media/celebrationcenter/images/global/celebrationtip/lunarnewyear.jpg" alt="Lunar New Year 2010" />'
		+'</td><td class="textStandard" align="left">'
		+'Create your own paper bag in Tigger-ific New Year style! Use them to carry your mandarin oranges when you go visiting.'
		+'<p> Download <a href="/DisneyChannel/playhouse/grownups/media/celebrationcenter/pdfs/lunarnewyear/ORANGE_BAG.pdf" target="_blank">here</a>.'
		+'');
	}
	else{
		document.write(''
		+'<img src="/DisneyChannel/playhouse/grownups/media/celebrationcenter/images/global/celebrationtip/mmch.jpg" alt="Celebration Tip" />'
		+'</td><td class="textStandard" align="left">'
		+'Bendy, swirly, squiggly straws in fun colors add a whimsical feel to any celebration.'
		+'');
	}
	
	document.write('</td><td width="10"></td></tr></table>');
}

function writeWatchMessage(which){
/*	if(which != null && which != ""){
		flashObj = new FlashObj(
			'/DisneyChannel/playhouse/grownups/media/celebrationcenter/flash/watch.swf', // swf
			'318', // width
			'64', // height
			'#FFFFFF', // background
			'', // version
			'decorationsSwf', // id
			'xmlConfig=/DisneyChannel/playhouse/media/global/watchmessages/config/config.xml&whichShow='+which, // flashVars
			true, // optional argument false = "no autoplay". true or blank = "autoplay"
			'', // base target
			'' //scale
			)
		flashObj.render(true,"opaque");
	}*/
}

function showHideContent(gif,item){
	var localItem = document.getElementById(item);
	var localGif = document.getElementById(gif);

	if(localItem.style.display == "none"){
		localItem.style.display = "block";
		localGif.src = "/DisneyChannel/playhouse/grownups/media/celebrationcenter/images/global/expand_minus.gif";
	}
	else{
		localItem.style.display = "none";
		localGif.src = "/DisneyChannel/playhouse/grownups/media/celebrationcenter/images/global/expand_plus.gif";
	}

}



//Sub Nav XML Functions 

var subNavCopyNum = 1;

function writeSubNav(xml,which){

	document.write('<div id="subNavCopy'+subNavCopyNum+'"></div>');

	
	//call function to load XML
	loadXMLDoc(xml,which,subNavCopyNum);
	
	subNavCopyNum++;

}

function loadXMLDoc(url,which,subNavCopyNum) {
	var req = false;
    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest && !(window.ActiveXObject)) {
    	try {
			req = new XMLHttpRequest();
        } catch(e) {
			req = false;
        }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
       	try {
        	req = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		req = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		req = false;
        	}
		}
    }
	if(req) {
		//processReqChange is a function call
		req.onreadystatechange = function(){if(req.readyState==4){processReqChange(req,which,subNavCopyNum)}};
		req.open("GET", url, true);
		req.send("");
	}
}

function processReqChange(req,which,subNavCopyNum) {

    
        // only if "OK"
        if (req.status == 200) {
        	//put all code here that will parse the XML
		
		var id=0;
		var text=1;
		var image=2;
		var pdf=3;
		var link=4;

		//firefox handles the child node numbers differently specifically 
		var dc_ie  = (navigator.appName.toLowerCase().indexOf("microsoft") != -1);
		
		if(!dc_ie)
		{
			id=id*2+1;
			text=text*2+1;
			image=image*2+1;
			pdf=pdf*2+1;
			link=link*2+1;
		}
		var prodList=req.responseXML.getElementsByTagName("item");
		
		var subNavId=req.responseXML.getElementsByTagName("id");
		subNavId=subNavId[0].childNodes[0].nodeValue;
		
		out="";

		if(which != "aggregate"){
			var out='<table width="430"><tr>';
		}
		else{
			var out='<table><tr>';
		}
		
		var num = 1;
		
		for(i=0;i<prodList.length;i++){
			
			if(prodList[i].attributes.getNamedItem("aggregate").value == "false" && which == "aggregate"){
				continue;
			}
			
			var idVar = prodList[i].childNodes[id].childNodes[0].nodeValue;
			var textVar = prodList[i].childNodes[text].childNodes[0].nodeValue;
			var imageVar = prodList[i].childNodes[image].childNodes[0].nodeValue;
			var pdfVar = prodList[i].childNodes[pdf].childNodes[0].nodeValue;
			var linkVar = prodList[i].childNodes[link].childNodes[0].nodeValue;
			
			
			if (idVar != which){
				
				out+='<td align="center" valign="top" width="104">';
				out+='<div class="marginCategoryItem">';
				out+='<a href="'+linkVar+'"><img src="'+imageVar+'" alt="'+textVar+'" /></a><br />';
				out+='<a href="'+pdfVar+'" target="_new" id="'+subNavId+i+'"><img src="/DisneyChannel/playhouse/grownups/media/celebrationcenter/images/global/print_off.jpg" alt="Print" id="i'+subNavId+i+'" /></a><br />';
				out+='<div class="widthCategoryItem"><span class="textSmall"><span class="textGray">'+textVar+'</span></span></div>';
				out+='</div>';
				out+='</td>';
				
				if(prodList.length<=4){
					if(i==prodList.length-1){
						for(i=num;i<5;i++){
							out+='<td align="center" valign="top" width="104"></td>';
						}
					}
				}

				if(num==4){
					out+='</tr><tr>';
					
					num=0;
				}			

				num++;
			}
			else{	
				if(prodList.length<=4){
					if(i==prodList.length-1){
						for(i=num;i<5;i++){
							out+='<td align="center" valign="top" width="104"></td>';
						}
					}
				}
			}
		}
		
		out+='</tr></table>';

		document.getElementById("subNavCopy"+subNavCopyNum).innerHTML=out;

        }
        
        else
        {
            alert("There was a problem retrieving the XML data:\n" +
                req.statusText);
        }
}