if (PG == undefined) var PG = {}; // Make sure the base namespace exists.

PG = Object.extend(PG, {
        Version: '1.0.0',
        emailUrl : 'http://www.post-gazette.com/storymailer2.asp?story=',
        currentItem : 'subblank',
        menu : [],
        monthNames : ['January','February','March','April','May','June','July','August','September','October','November','December'],
        dayNames : ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'],

        currentWeatherId : 0,
		snapBackHover : 0,
        headerHover : 0,
        widgetMenuTimer : 0,
        headerCounter: 0,
        mySection: null,
        domain: ".post-gazette.com",
       // domain: ".dev.deeplocal.com",
		foundMe: false,
	    proxyURL : '/apps/PageData/',        
		//proxyURL : '/approxy.php',	
        aspProxyURL : '/includes/ajax/ajaxproxy.asp',
		relatedStoryURL : '/apps/pagedata/RelatedItems.aspx',
		widgetSaveEndpoint: '/apps/PageData/SaveWidgetInfo.aspx',
		lightboxLink : undefined, 

		
		//relatedStoryURL : '/approxy2.php',
		//relatedStoryURL : '/items.html',
		cX : 0,
		cY : 0, 
		rX : 0,
		rY : 0,
		widgetElement: null,
		
        proxyRequestID : {
                                        getStoryLeftRail : 3,
                                        getPageLastUpdate : 4,
                                        getAdLocations : 5,
                                        getAPRSS : 6,
                                        OASrequest : 7
                                },


        handleSearchForm : function(inputArea, focused){
                if(inputArea.value == "Search Post-Gazette NOW" && focused){
                        inputArea.value = "";
                        return;
                }

                if(inputArea.value != "Search Post-Gazette NOW" && focused){
                        return;
                }

                if(inputArea.value == "" && !focused){
                        inputArea.value = "Search Post-Gazette NOW";
                        return;
                }


        },
        
        getHeaderDate : function(){
                var rightNow = new Date();
                return this.dayNames[rightNow.getDay()] + " " + this.monthNames[rightNow.getMonth()] + " " + rightNow.getDate() + ", " + rightNow.getFullYear();

        },

        switchTab : function (event){
                var heading = Event.element(event);
                var otherHeadings = heading.siblings();

                var list = $(heading.id + '_list');
                var otherLists = list.siblings();

                for(var o = 0; o < otherHeadings.size(); o++){
                        otherHeadings[o].removeClassName('tab_box_header_selected');
                        otherHeadings[o].addClassName('tab_box_header_unselected');
                }
                heading.removeClassName('tab_box_header_unselected');
                heading.addClassName('tab_box_header_selected');

                for(var o = 0; o < otherLists.size(); o++){
                        otherLists[o].setStyle({display:'none'});
                }

                list.setStyle({display:'block'});


        },

        insertTimeUpdated : function(){
                // JLF 20070823 - Old proxy.
                //var endpointURL = PG.proxyURL + "?requestID=" + PG.proxyRequestID.getPageLastUpdate + "&params=" + PG.getItemId(); 
                var endpointURL = PG.proxyURL + "default.asmx/GetDateLastUpdated";
                new Ajax.Request(endpointURL, { method:'get', onSuccess:PG.timeUpdatedCallback});
        },
         
        timeUpdatedCallback : function(timeXml){
			
                try{
                        var timedoc = XMLParse.xml2ObjArray(timeXml.responseXML, "LastUpdatedObject");
                        } catch(e){
                }

                var updatedTextArea = document.getElementById('updateddisplay');
                var articleLink;
                var updatedSpan;
				
                if(typeof timedoc[0].LastUpdatedDate != undefined){
                        updatedSpan = document.createElement('span');

                        if(typeof timedoc[0].LastUpdatedArticleURL != 'undefined'){
                                articleLink = document.createElement('a');
                                articleLink.href = timedoc[0].LastUpdatedArticleURL;
                        }

                        var updatedLast = Date.parse(timedoc[0].LastUpdatedDate);

                        var updatedDate = new Date();

                        updatedDate.setTime(updatedLast);

                        var hour = updatedDate.getHours();
                        var amPm = 'a.m.';

                        if(hour >= 12){
                                if(hour > 12) { hour -= 12;     }
                                amPm = 'p.m.';
                        } 
                        if(hour == 0){
                                hour = 12;
                        }


                        var minute = updatedDate.getMinutes();
                        if(minute < 10){
                                minute = '0' + minute;
                        } 
                        if(minute == 0){
                                minute = '00';
                        }

                        //var updateString = "Updated: " + PG.monthNames[updatedDate.getMonth()] + " " + updatedDate.getDate() + ", " + hour + ":" + minute + " " + amPm;
                        var updateString = "Updated: " + hour + ":" + minute + " " + amPm;
                        updatedSpan.innerHTML = updateString;

                        if(typeof articleLink != 'undefined'){
                                articleLink.appendChild(updatedSpan);
                                updatedTextArea.appendChild(articleLink);

                        } else {
                                updatedTextArea.appendChild(updatedSpan);
                        }
                }
                
       
                
        },

        getItemId : function(){
                var metatags = document.getElementsByTagName('META');
                var i = 0;
                for(i = 0; i < metatags.length; i++){
                        if(metatags[i].name == 'itemid'){
                                return  metatags[i].content;
                        }
                }
         
                return document.URL.substring(document.URL.lastIndexOf('/')+1, document.URL.lastIndexOf('-'));
         
         },
         
         setHeaderSection : function(){

                var titleSection = document.getElementById('headersectiontitle');
						
					

						
						var myHeaderString = PG.buildHeaderString(PG.sectionMappingCode);
						
						titleSection.innerHTML=myHeaderString;
						
						if( document.getElementById('topnav_'+PG.topLevelParent)){

							topLevelParentId =  'topnav_'+PG.topLevelParent;
							
						}else{
							topLevelParentId = 'topnav_0';
						}
						
						var topNav = document.getElementById(topLevelParentId);
						
						topNav.className='topselecteditem';
						
						PG.mySection = topNav;
                         
                         this.submenuCommit(PG.mySection);						

               
         },
         
        goSomewhere: function(url){
        
        	window.location = url;
        },
        	
        	
        submenuClear : function(event){
                if(PG.headerHover !=0){ clearTimeout(PG.headerHover); }
				
                if(typeof event != 'undefined'){
						  var call = "PG.submenuCommit('"+PG.mySection.id+"')";
						  PG.headerHover = window.setTimeout(call,900);
						 return;
     				} //end undefied
         
         },
         
         submenuTrigger : function(section){
                

                if(PG.headerHover != 0) {
                
                clearTimeout(PG.headerHover)  
                
                };
                
                
                var call = "PG.submenuCommit('" + section.id + "')";
                //Event.observe(section, 'mouseout', PG.submenuClear);
                PG.headerHover = window.setTimeout(call, 250);
                
                var sect = document.getElementById("topnavbar");
                Event.observe(sect, 'mouseout', PG.submenuClear);
                
                var subsect =  document.getElementById("subcontainer");

				Event.observe(subsect,'mouseover', PG.subcontainerHoverOnFlip);
                Event.observe(subsect,'mouseout', PG.subcontainerHoverOffFlip);
                Event.observe(subsect,'mouseout', PG.submenuClear);

                var allSubNav = $$('.subnavitem');
					

                allSubNav.each(function(nav) {	
                Event.observe(nav,'mouseover', PG.subcontainerHoverOnFlip);
                Event.observe(nav,'mouseout', PG.subcontainerHoverOffFlip);
//                Event.observe(nav,'mouseout', PG.submenuClear);

                });
                
         },
         
         
         subcontainerHoverOnFlip : function(event) {

		
                 if(PG.headerHover != 0) {
                	clearTimeout(PG.headerHover)                 
                };
                 

         		
          
          
         },

      
        subcontainerHoverOffFlip : function (event) {

         	 if(PG.headerHover != 0) {  clearTimeout(PG.headerHover) };
         	 PG.submenuClear(event);
			
         },    

         submenuCommit : function(sectionId){
                var section = $(sectionId);
                var sect = document.getElementById("subcontainer");
                if(this.currentItem != 'subblank'){
                        var oldSection = document.getElementById(this.currentItem);
                        //oldSection.className = 'topnavitem';
                }
         
                var showSection = document.getElementById(section.id + "_nav");
                //section.className = 'topselecteditem';
                this.currentItem = section.id;
         
                sect.innerHTML = showSection.innerHTML;
         },
         
         buildMenu : function(header){
                
                
         		//Moved from set section header.       
                var metatags = document.getElementsByTagName('META');

         		for(i = 0; i < metatags.length; i++){
         		
                        if(metatags[i].name == 'mappingCode'){
							PG.sectionMappingCode = metatags[i].content;
							PG.foundMe = true;
						}
							
							
						
						
						
				}
         	
				if(PG.foundMe==false){
					
							var myurl = window.location.pathname;

							
							var myurlarr = myurl.split("/");
							
							var lastBit = myurlarr[myurlarr.length-1];
							var codes = lastBit.split("-");
							var sectionCode = 0;
							
							if(codes.length > 1){
								 sectionCode = codes[1].split(".")[0];							
							
							}
							
							if(sectionCode > 0){
							
								PG.sectionMappingCode = sectionCode;
								PG.foundMe = true;
							}else{
						        PG.sectionMappingCode = 1;
							}
				}
         
         				
         			
         			
                for (var i in PG.topnavids) {
                		
                		var toptemp = document.createElement("div");
                        toptemp.style.display='none';
                        toptemp.id = 'topnav_'+PG.topnavids[i]+ '_nav';
                        toptemp.className = 'secondary';
 
 						
 						
                        var subtemp = document.createElement("div");
                        toptemp.appendChild(subtemp);
                         subtemp.className = 'subnavitem';
                         
                        if(typeof PG.subnavids[PG.topnavids[i]] != "undefined"){

                                for(j = 0; j < PG.subnavids[PG.topnavids[i]].length; j++){
                                		var myId =  PG.subnavids[PG.topnavids[i]][j];
                                		
                                        //Need to figure this out for inside selection...
                                        
                                        var tempLinkHREF = PG.sections[myId].URL;
                                        
                                        	if(tempLinkHREF.indexOf("http:") > -1){
                                        		//use this one
                                        	}else{
                                        		
                                        		if(window.location.host.indexOf("pg.dev") > -1 ){
	                                        		tempLinkHREF = "http://pg.dev.deeplocal.com"+tempLinkHREF;
                                        		}else if(window.location.host.indexOf("pgtest") > -1){
                                        		tempLinkHREF = "http://pgtest.post-gazette.com"+tempLinkHREF;
                                        		}else{
                                        			tempLinkHREF = "http://www.post-gazette.com"+tempLinkHREF;
                                        		}
                                        		
                                        	}
                                        
                                        if(myId == PG.sectionMappingCode || (PG.getParentTrail(PG.sectionMappingCode).indexOf(myId) > -1)){
                                        
												var mydiv = document.createElement("div");
												
												mydiv.className='subnavselecteditem';
											
					  						  var templink = document.createElement("a");

//		                                        templink.href = PG.sections[myId].URL;
												templink.href = tempLinkHREF;		                                        
												templink.innerHTML = PG.sections[myId].Name;												
												mydiv.appendChild(templink);										
		                                        subtemp.appendChild(mydiv);
		                                  

										}else{                                    
        	                                var templink = document.createElement("a");
            	                           // templink.href = PG.sections[myId].URL;
            	                           	templink.href = tempLinkHREF;
											templink.innerHTML = PG.sections[myId].Name;

									
                                        subtemp.appendChild(templink);
                                        }
                                }

                                header.appendChild(toptemp);
                        }
                }
                this.setHeaderSection();
                
              var myInside =   PG.getInsideSection(PG.sectionMappingCode);
				if(myInside > -1){
					
					PG.displayInsideSection(myInside);
				
				}
				
         },     
         
         displayInsideSection : function (myInside){
         		
         		
         		var insideids = PG.inside_section_subnavids[myInside];
         		
         		var myInsideString = "";
         		
         		var myInsideGroup = PG.getSection(myInside);
         		
         		myInsideString = "<div class='inside_section'>Inside <a href='"+myInsideGroup.URL+"'>"+
         							myInsideGroup.Name+"</a>: </div> \n";
         		
         		insideids.each(function(sectionid){
					/*
					<div class="inside_nav_item"><a href="#">GOLF</a></div>
					<div class="inside_nav_item"><a href="#">Motor Sports</a></div>
					<div class="inside_nav_item"><a href="#">Motor Sports</a></div>
         			*/
         			
         			var section = PG.getSection(sectionid);
         			var myStyle ="";
         			if(sectionid == PG.sectionMappingCode){
         					myStyle = "selected_inside_nav_item";
         			}else{
         					myStyle = "inside_nav_item";
         			}
         			myInsideString = myInsideString +
         					"<div class='"+myStyle+"'><a href='" + section.URL + "'>"+section.Name+"</a></div> \n"; 	
         			
         		
         		});
         		
         			
         			
         			$('inside_nav').innerHTML = myInsideString;
         			
      
         		$('inside_nav').setStyle({display: 'block'});	
         
         
         },
         
         emailPage : function(){
                var thisPage = escape(document.URL);
                document.location = this.emailUrl + thisPage;
         },
         
         toggleBioLength: function(event){
                var expandText = Event.element(event);
                var bioid = expandText.id.substring(10,expandText.id.length);
                var authorDiv = document.getElementById('author_' + bioid);
         
                if(authorDiv.style.height != 'auto'){
                        authorDiv.style.height = 'auto';
                        expandText.innerHTML = 'Less &raquo;';
                } else {
                        authorDiv.style.height = '7em';
                        expandText.innerHTML = 'More &raquo;';
                }
         },
         
            populateLeftRail : function(){
   			
         		var endpointURL = PG.relatedStoryURL + "?lngItemID=" + PG.getItemId();      		
         		//var endpointURL = PG.relatedStoryURL + "?lngItemID=823399";
         		PG.populateLeftRailActionItems();
                new Ajax.Request(endpointURL, { method:'get', onSuccess:PG.jsonLeftRailCallback});
         },
         
         
         populateLeftRailActionItems : function(){
         
          		    var storyLeftRailAbout = document.createElement('div');
                        storyLeftRailAbout.className = 'story_leftrail_about';	
						storyLeftRailAbout.id = 'story_left_rail_about_id';
						
					
						var storyLeftRailAction = document.createElement('div');
						
						storyLeftRailAction.className = 'mod_widget';
						
						var actionTitleDiv = document.createElement('div');
							actionTitleDiv.className='story_mod_widget_header';
						
						var actionIconDiv = document.createElement("div");
							actionIconDiv.className='mod_widget_header_badge';
												
									
						var actionTitleText = document.createElement("div");
							actionTitleText.innerHTML = 'Article Tools';
							actionTitleText.className='mod_widget_header_title';		
									
							actionTitleDiv.appendChild(actionIconDiv);
							actionTitleDiv.appendChild(actionTitleText);
						
							
						var actionBody = document.createElement('div');
							actionBody.className='story_leftrail_attached_media_container';
							
							
					if($$('#newshole .story_headline')[0]){
						var diggHeadline = escape($$('#newshole .story_headline')[0].innerHTML).substr(0,75);		
						var diggBodyTxt = escape($$('.story_body p')[0].innerHTML).substr(0,350);				
						}
						
					var diggSrcUrl = escape(window.location);
								
								
								
					var diggURL = "http://digg.com/submit?url="+diggSrcUrl+
									"&title="+diggHeadline+"&bodytext="+diggBodyTxt+"&media=NEWS";
								


								

								
							var emailActionImage = document.createElement('img');
								emailActionImage.src = '/includes/2007design/images/icons/email.png';
								emailActionImage.setAttribute("onclick","PG.emailPage();");
								
							var printActionImage = document.createElement('img');
								printActionImage.src = '/includes/2007design/images/icons/print.png';
								printActionImage.setAttribute("onclick","window.print();");
								
						//	var diggActionImageA = document.createElement("a");
						//		diggActionImageA.setAttribute("href",diggURL);
								
								
							var diggActionImage = document.createElement('img');
								diggActionImage.src = '/includes/2007design/images/icons/16x16-digg-guy.png';
								diggActionImage.setAttribute("onclick","PG.goSomewhere('"+diggURL+"');");
								
						//		diggActionImageA.appendChild(diggActionImage);
								
							
							var emailAction = document.createElement('div');
								emailAction.id='story_left_email_action';
								emailAction.className='story_left_action story_action';
							
							var emailLink = document.createElement('a');
								emailLink.setAttribute("onclick","PG.emailPage();");
								emailLink.setAttribute("href","#");
	
							var emailText = document.createTextNode("E-mail Article");
								
								emailLink.appendChild(emailText);
								
								emailAction.appendChild(emailActionImage);
								emailAction.appendChild(emailLink);
								
								
							var printAction =  document.createElement('div');
								printAction.id = 'story_left_print_action';
								printAction.className = 'story_left_action story_action';
								
							var printLink = document.createElement("a");
								printLink.setAttribute("onclick","window.print();");
								printLink.setAttribute("href","#");
								
							var printText = document.createTextNode('Print Article');
								
								printLink.appendChild(printText);
								printAction.appendChild(printActionImage);
								printAction.appendChild(printLink);
				
				
							

							
							var diggAction = document.createElement('div');
								diggAction.id = 'story_left_digg_action';
								diggAction.className = 'story_left_action story_action';
								
							var diggLink = document.createElement('a');
								
							var diggText = document.createTextNode('Digg This');
								diggAction.appendChild(diggActionImage);
								diggLink.appendChild(diggText);
							
								
								diggLink.setAttribute("href",diggURL);				
											
								
								diggAction.appendChild(diggLink); 

								actionBody.appendChild(emailAction);
								actionBody.appendChild(printAction);
								actionBody.appendChild(diggAction);
							
							storyLeftRailAction.appendChild(actionTitleDiv);
							storyLeftRailAction.appendChild(actionBody);
							storyLeftRailAbout.appendChild(storyLeftRailAction);
								     	
         	document.getElementById('leftrail').insertBefore(storyLeftRailAbout, document.getElementById('left_spacer'));
         			
         },
         
         jsonLeftRailCallback : function(resp){
                var bios = [];
                var toggles = [];//can't attach events until its attached to the dom
                var videos = [];
                var photos = [];
                var audio = [];
                var links = [];

                try{
	                var res = eval(resp.responseText);
                } catch(e){
	              
                }

                if(res.size() > 0){
                        //If there is related info, build the about this story box, otherwise, dont bother.
				try{

						var storyLeftRailAbout = document.getElementById('story_left_rail_about_id');			
								
												
						
                        var storyLeftRailAboutHeader = document.createElement('div');
                        storyLeftRailAboutHeader.className = 'story_leftrail_about_header';
                        storyLeftRailAboutHeader.innerHTML = '';

                      //  storyLeftRailAbout.appendChild(storyLeftRailAboutHeader);
						
						var photoCount = 0;
						var photoLimit = 3;
						
                        //loop through the items returned and build the list
                        for(var i =0; i < res.size(); i++) {
								
                                var item = res[i];
                                switch(item.itemType){

                                        case 'bio':
                                        var thisbio = document.createElement("div");
	
												thisbio.className = 'mod_widget_author';											
												var thisBioImg = document.createElement("img");
													
                                                if(typeof item.bioHeadshotPhotoURL != 'undefined'){

                                                        thisBioImg.alt = item.bioAuthorName;
                                                        thisBioImg.src = item.bioHeadshotPhotoURL;
                                                        	thisbio.appendChild(thisBioImg);
                                                }else{
                                                		thisBioImg.alt = item.bioAuthorName;
                                                		thisBioImg.src = '/includes/2007design/images/headshots/person50.png';
                                                		thisbio.className = 'mod_widget_author_noimage';
                                                }
														/* do stuff on bio image */		
												
												
												var thisHeadShotName = document.createElement("div");
												 thisHeadShotName.className = 'mod_widget_headshot_name';
												
												if(typeof item.bioHeadshotPhotoURL == 'undefined'){
												//	thisHeadShotName.className = "mod_widget_headshot_name_noimage";
												
													thisHeadShotName.style.paddingTop = "0px";
													
												}
												
												var thisHeadShotFirstName = document.createElement("div");
												var thisHeadShotLastName = document.createElement("div");
												
												thisHeadShotFirstName.className='mod_widget_headshot_name_smTxt';
												thisHeadShotLastName.className = 'mod_widget_headshot_name_bigTxt';
												                                               
  	                                            var authorFirstName = item.bioAuthorName.split(" ")[0];
                                                var authorLastName  = item.bioAuthorName.split(" ")[1];
                                                
													thisHeadShotFirstName.innerHTML = authorFirstName;
													thisHeadShotLastName.innerHTML = authorLastName;
	
													thisHeadShotName.appendChild(thisHeadShotFirstName);
													thisHeadShotName.appendChild(thisHeadShotLastName);	
												
												thisbio.appendChild(thisHeadShotName);
												
				                         
				                         		//authorHolder.appendChild(thisbio);
				                         		
											 if(typeof item.bioAuthorEmail != 'undefined'){
											
												var bioContact = document.createElement("div");
												
													bioContact.id = 'email_author_'+ item.externalID;
													bioContact.className='mod_widget_author_contact story_action';
												
													var bioContactEmailImg = document.createElement("img");
													bioContactEmailImg.alt='email';
													bioContactEmailImg.src='/includes/2007design/images/icons/white/email.png';
													
													var bioContactEmailAction = document.createElement("a");
													bioContactEmailAction.setAttribute( "href", "mailto:"+item.bioAuthorEmail );
													bioContactEmailAction.innerHTML = "Email Author";
													

													bioContact.appendChild(bioContactEmailImg);
													bioContact.appendChild(bioContactEmailAction);
													thisbio.appendChild(bioContact);

											

											 }

											
											if(typeof item.bioAuthorPhone!="undefined" ){
												var bioPhone = document.createElement("div");
												bioPhone.id = 'phone_'+ item.externalID;
												bioPhone.className="mod_widget_author_contact story_action";
												var bioContactPhoneImg = document.createElement("img");
												bioContactPhoneImg.alt = item.bioAuthorPhone
												bioContactPhoneImg.src = '/includes/2007design/images/icons/white/callreporter.png';
												bioPhone.appendChild(bioContactPhoneImg);
												var phoneText = document.createTextNode("Call "+item.bioAuthorPhone);
												bioPhone.appendChild(phoneText);
												thisbio.appendChild(bioPhone);
											}

                                                var biotext = document.createElement("div");
												biotext.id = 'author_' + item.externalID;
												biotext.className = 'story_leftrail_author_about';
                                                biotext.innerHTML = item.bioText.unescapeHTML().stripTags();
                                                thisbio.appendChild(biotext);

                                                toggles.push('biotoggle_' + item.externalID);
											//	authorHolder.appendChild(thisbio);
                                                bios.push(thisbio);
                                                break;

                                        case 'audio':
                                                var titleLink = document.createElement('a');
                                                titleLink.href = item.itemURL;
                                                titleLink.innerHTML = item.title;
                                                audio.push(titleLink);
                                                break;

                                        case 'video':
                                        
                                        
                                       		 var mod_widget_item = document.createElement('div');
												mod_widget_item.className='mod_widget_item';		
												
												var thumbnail = document.createElement('div');
												thumbnail.className='index_video_thumbnail_left';
												
												 var imageLink = document.createElement('a');
                                                imageLink.href = "" + item.itemURL;
                                                imageLink.rel = 'lightbox[' + PG.getItemId() + ']';
                                                
                                                var imageLink2 = document.createElement('a');
                                                imageLink2.href = "" + item.itemURL;
                                                imageLink2.rel = 'lightbox[' + PG.getItemId() + ']';

                                                var popupText = '';

                                                if(typeof item.photoCredit != "undefined"){
                                                     imageLink.title =  item.photoCredit + "<br/>";
                                                }

                                                if(typeof item.photoCaption != "undefined"){
                                                     imageLink.title += item.photoCaption;
                                                }

												var imageThumb = document.createElement('img');
													imageThumb.alt=item.title;
													imageThumb.src=item.thumbnailURL;
													imageThumb.setAttribute( 'style', 'width: 148px; margin-bottom: 4px;');
												
												
												var captionTxt = document.createTextNode(item.title);
												

												imageLink.appendChild(imageThumb);
												
												imageLink2.appendChild(captionTxt);
												
												thumbnail.appendChild(imageLink);
												
												var mybr = document.createElement("br");
												thumbnail.appendChild(mybr);
												thumbnail.appendChild(imageLink2);
												mod_widget_item.appendChild(thumbnail);

                                        
                                        
                                        		
                                        		
                                        		
                                            //    var titleLink = document.createElement('a');
                                            //    titleLink.href = item.itemURL;
                                            //    titleLink.innerHTML = item.title;
                                                videos.push(mod_widget_item);
                                                break;

                                        case 'image':
												var mod_widget_item = document.createElement('div');
												mod_widget_item.className='mod_widget_item';
												
												
												if(photoCount == 0){
												   mod_widget_item.style.display='none';
												   PG.lightboxLink='lightbox['+PG.getItemId() + ']';
												   PG.lightboxUrl = '' + item.itemURL;
												}
												
												
											if(photoCount <= (photoLimit - 1)){
	
												var thumbnail = document.createElement('div');
												thumbnail.className='index_photo_thumbnail_left';
												
												
												 var imageLink = document.createElement('a');
                                                imageLink.href = "" + item.itemURL;

                                                imageLink.rel = 'lightbox[' + PG.getItemId() + ']';
                                                var popupText = '';

												
                                                if(typeof item.photoCredit != "undefined"){
                                                     imageLink.title =  item.photoCredit + "<br/>";
                                                }

                                                if(typeof item.photoCaption != "undefined"){
                                                     imageLink.title += item.photoCaption;
                                                }

												var imageThumb = document.createElement('img');
													imageThumb.alt=item.title;
													
													//var myString = "http://www.ddd.ccc/3424/523/2some_thing_203.jpg";

													item.itemURL = item.itemURL.replace(/\_[0-9]{3}\.jpg/,'_160.jpg');

													
													
													imageThumb.src=item.itemURL;
													imageThumb.setAttribute( 'style', 'width: 160px; margin-bottom: 4px;');
												
												/*
												var captionTxt = document.createTextNode(item.title);
												*/

												imageLink.appendChild(imageThumb);
												/*
												imageLink.appendChild(captionTxt);
												*/
												thumbnail.appendChild(imageLink);
												mod_widget_item.appendChild(thumbnail);
												photoCount++;
												
											}else{
												
												 var titleLink = document.createElement('a');
                                                titleLink.href = "" + item.itemURL;
                                                titleLink.rel = 'lightbox[' + PG.getItemId() + ']';
                                                var popupText = '';

                                                if(typeof item.PhotoCredit != "undefined"){
                                                     titleLink.title =  item.PhotoCredit + "<br/>";
                                                }

                                                if(typeof item.PhotoCaption != "undefined"){
                                                     titleLink.title += item.PhotoCaption;
                                                }

                                                titleLink.innerHTML = item.title;
												mod_widget_item.appendChild(titleLink);
												
											}
                                                photos.push(mod_widget_item);

                                         break;
                                        case 'link':
                                                var link = document.createElement('a');
                                                link.href = item.itemURL;
                                                link.innerHTML = item.title;
                                                links.push(link);
                                                break;

                                        default :
                                                //do nothing
                                                break;

                                }
                        }
    					
    					try{

						if(bios.size() > 0){
							var authorHolder = document.createElement("div");
							authorHolder.className = 'mod_widget';

							var authorTitleDiv = document.createElement('div');
							authorTitleDiv.className='story_mod_widget_header';
						
							var authorIconDiv = document.createElement("div");
							authorIconDiv.className='mod_widget_header_badge';
							

							
							var titleText = document.createElement("div");
							titleText.innerHTML = 'About the Author';
							titleText.className='mod_widget_header_title';												

							authorTitleDiv.appendChild(authorIconDiv);
							authorTitleDiv.appendChild(titleText);
							authorHolder.appendChild(authorTitleDiv);
							



											
                        for(var b = 0; b < bios.size(); b++){
                                var biotoggle = document.createElement("div");
                                biotoggle.className = 'biotoggle';
                                biotoggle.id = toggles[b];
                                biotoggle.innerHTML = 'More &raquo;';
//								bios[b].appendChild(biotoggle);
								authorHolder.appendChild(bios[b]);
								authorHolder.appendChild(biotoggle);
                        }
							 storyLeftRailAbout.appendChild(authorHolder);
	
   						}
					}catch(e){
					
					}

                        if(audio.size() > 0){
 								var relatedAudio = document.createElement('div');
                                relatedAudio.className = 'mod_widget';

                                var audioTitleDiv = document.createElement('div');
                                audioTitleDiv.className='story_mod_widget_header';
                                
								
                                var audioIcon = document.createElement("img");
                                audioIcon.src = '/includes/2007design/images/icons/white/audio.png';
                                audioIcon.alt = 'photo';
						//		audioIcon.style( 'style', 'margin-right: 5px;');

								var sectionHeaderLink = document.createElement('span');
									sectionHeaderLink.className = 'story_leftrail_attached_media_header_link';

								/*	
								var headerLink = document.createElement('a');
									headerLink.setAttribute('href','/multimedia/');
									headerLink.innerHTML = 'media center';

								//	sectionHeaderLink.appendChild(headerLink);
								*/
								
                                var titleText = document.createElement("div");
                                var titleWords = document.createTextNode("Audio");


                             //   titleText.innerHTML = 'Images';
                                
								titleText.className = 'mod_widget_header_title';
                                titleText.appendChild(audioIcon);
								titleText.appendChild(titleWords);
								titleText.appendChild(sectionHeaderLink);


								audioTitleDiv.appendChild(titleText);
                                relatedAudio.appendChild(audioTitleDiv);



								var linkContainer = document.createElement("div");
								linkContainer.className = 'story_leftrail_attached_media_container';
								
                                for(var a = 0; a < audio.size(); a++){
                                        var audioItem = document.createElement('div');
                                        audioItem.className = 'story_link';

                                        audioItem.appendChild(audio[a]);
                                        linkContainer.appendChild(audioItem);
                                }
                                relatedAudio.appendChild(linkContainer);
                                storyLeftRailAbout.appendChild(relatedAudio);
                        }

                      
                        if(videos.size() > 0){
                        
  

 
								
								
							 var relatedVideo = document.createElement('div');
                                relatedVideo.className = 'mod_widget';

                                var videoTitleDiv = document.createElement('div');
                                videoTitleDiv.className='story_mod_widget_header';
                                
								
                                var videoIcon = document.createElement("img");
                                videoIcon.src = '/includes/2007design/images/icons/white/video.png';
                                videoIcon.alt = 'photo';
								videoIcon.setAttribute( 'style', 'margin-right: 5px;');

								var sectionHeaderLink = document.createElement('span');
									sectionHeaderLink.className = 'story_leftrail_attached_media_header_link';


								var headerLink = document.createElement('a');
									headerLink.setAttribute('href','/multimedia/');
									headerLink.innerHTML = 'media center';

									sectionHeaderLink.appendChild(headerLink);

                                var titleText = document.createElement("div");
                                var titleWords = document.createTextNode("Video");


                             //   titleText.innerHTML = 'Images';
                                
								titleText.className = 'mod_widget_header_title';
                                titleText.appendChild(videoIcon);
								titleText.appendChild(titleWords);
								titleText.appendChild(sectionHeaderLink);


								videoTitleDiv.appendChild(titleText);
                                relatedVideo.appendChild(videoTitleDiv);

								var linkContainer = document.createElement("div");
								linkContainer.className = 'story_leftrail_attached_media_container';
								

                                for(var v = 0; v < videos.size(); v++){
                                        var videoItem = document.createElement('div');
                                        videoItem.className = 'story_link';
                                        videoItem.appendChild(videos[v]);
                                        linkContainer.appendChild(videoItem);
                                }
                                relatedVideo.appendChild(linkContainer);
                                storyLeftRailAbout.appendChild(relatedVideo);
                        }

  						if(photos.size() > 0){
                                var relatedPhoto = document.createElement('div');
                                relatedPhoto.className = 'mod_widget';

                                var photoTitleDiv = document.createElement('div');
                                photoTitleDiv.className='story_mod_widget_header';
                                
								
                                var photoIcon = document.createElement("img");
                                photoIcon.src = '/includes/2007design/images/icons/white/photo.png';
                                photoIcon.alt = 'photo';
								photoIcon.setAttribute( 'style', 'margin-right: 5px;');

								var sectionHeaderLink = document.createElement('span');
									sectionHeaderLink.className = 'story_leftrail_attached_media_header_link';


								var headerLink = document.createElement('a');
									headerLink.setAttribute('href','#');
																		
									headerLink.innerHTML = 'view slideshow';

									sectionHeaderLink.appendChild(headerLink);

                                var titleText = document.createElement("div");
                                var titleWords = document.createTextNode("Images");


                             //   titleText.innerHTML = 'Images';
                                
								titleText.className = 'mod_widget_header_title';
                                titleText.appendChild(photoIcon);
								titleText.appendChild(titleWords);
							//	titleText.appendChild(sectionHeaderLink);


								photoTitleDiv.appendChild(titleText);
                                relatedPhoto.appendChild(photoTitleDiv);
								//photoTitleDiv.appendChild(photoIconDiv);
								var linkContainer = document.createElement("div");
								linkContainer.className = 'story_leftrail_attached_media_container';
								

								/*    PUT the code here for the  Show x number of images */
								
								var viewSlideShowDiv = document.createElement("div");
									viewSlideShowDiv.className = "mod_widget_item";
									
								var slideShowView = document.createElement("a");
									slideShowView.href= PG.lightboxUrl;
									 slideShowView.rel=PG.lightboxLink;

									//PG.lightbox =myLightbox;
									var displayString = "View all images";
									
									slideShowView.innerHTML = displayString;

								viewSlideShowDiv.appendChild(slideShowView);
								
								linkContainer.appendChild(viewSlideShowDiv);
								
								


                                for(var p = 0; p < photos.size(); p++){
                                       /*
										var photoItem = document.createElement('div');
                                        photoItem.className = 'story_link';
                                        photoItem.appendChild(photos[p]);
                                        */
										linkContainer.appendChild(photos[p]);
                                }
                                relatedPhoto.appendChild(linkContainer);
                                storyLeftRailAbout.appendChild(relatedPhoto);
                        }


						                     if(links.size() > 0){

                                var relatedLinks = document.createElement('div');
                                relatedLinks.className = 'mod_widget';


                                var linksTitleDiv = document.createElement('div');
                                linksTitleDiv.className='story_mod_widget_header';
                                
                                var linksIconDiv = document.createElement("div");
                                linksIconDiv.className='mod_widget_header_badge';                        
                                
                                var titleText = document.createElement("div");
                                titleText.innerHTML = 'Related Stories';
                                titleText.className = 'mod_widget_header_title';
                                     
								linksTitleDiv.appendChild(linksIconDiv);
                                linksTitleDiv.appendChild(titleText);
                                relatedLinks.appendChild(linksTitleDiv);
                                
								var linkContainer = document.createElement("div");
								linkContainer.className = 'story_leftrail_attached_media_container';
								
                                for(var l = 0; l < links.size(); l++){
                                        var linkItem = document.createElement('div');
                                        linkItem.className = 'story_link';

                                        linkItem.appendChild(links[l]);
                                        linkContainer.appendChild(linkItem);
                                }
                                relatedLinks.appendChild(linkContainer);
                                storyLeftRailAbout.appendChild(relatedLinks);

                        }
// Moved this up to populateLeftRail
//                        document.getElementById('leftrail').insertBefore(storyLeftRailAbout, document.getElementById('left_spacer'));

                        for(var t = 0; t < toggles.size(); t++){
                                Event.observe($(toggles[t]), 'click', PG.toggleBioLength);
                        }
                        myLightbox.updateImageList();
                        //PG.lightbox = myLightbox;
                    }catch(e){
                    
                    }    
                }

                if(typeof PG.getRSSLink() != 'undefined'){

                        var relatedStoriesListSection = document.createElement("div");

                        relatedStoriesListSection.className='story_leftrail_more_stories index_lower_newslist';
                        relatedStoriesListSection.id = 'story_leftrail_more_stories';

                        var relatedStoriesListHeader = document.createElement("div");
                        relatedStoriesListHeader.innerHTML = 'More stories like this';
                        relatedStoriesListHeader.className = 'story_mod_widget_header';
                        relatedStoriesListHeader.id = 'story_leftrail_more_stories_header';
                        var rSLDiv = document.createElement("div");
                        rSLDiv.className = 'story_leftrail_attached_media_container';

                        var relatedStoriesList = document.createElement("ul");
                        relatedStoriesList.id='story_leftrail_more_stories_list';

                        relatedStoriesListSection.appendChild(relatedStoriesListHeader);
                        rSLDiv.appendChild(relatedStoriesList);
                        relatedStoriesListSection.appendChild(rSLDiv);

                        var separator = document.createElement("div");
                        separator.className = 'story_separator';
                        document.getElementById('leftrail').insertBefore(separator, document.getElementById ('left_spacer'));
                        
                        document.getElementById('leftrail').insertBefore(relatedStoriesListSection, document.getElementById('left_spacer'));

                        try{
                                new Ajax.Request(PG.getRSSLink(), { method:'get', onSuccess:function(transport){PG.populateRSSList('story_leftrail_more_stories',transport, '', 5);}});                                
                        } catch(e){
                        }
                }
        
        
         	
        		$$('.mod_widget').each(function(items){
        		    $(items).setStyle({
 					 'float': 'left'});		
        		});
        	
        		
        
        
         },
                  
         getRSSLink : function(){
                        var links = document.getElementsByTagName("link");

                for(var i = 0; i < links.length; i++){
                        var checkLink = links[i];
                        if(checkLink.type == 'application/rss+xml'){
                                if(checkLink.rel != ''){
                                        var cleaned = checkLink.href;
         
                                        if(checkLink.href.indexOf('http://')==0){
                                                cleaned = checkLink.href.substring(7, cleaned.length);
                                                cleaned = cleaned.substring(document.domain.length, cleaned.length);
                                        }
                                        return cleaned;
                                }
                        }
                }
         },
         
         updateRSSLink : function(){
                var rssMenuEntry = document.getElementById('pg_rsslink');

                if(typeof rssMenuEntry != 'undefined'){
                        for(var r = 0; r < rssMenuEntry.childNodes.length; r++){ 
                                var checkNode = rssMenuEntry.childNodes[r];
                                if(checkNode.tagName == "A"){
                                        var pglink = PG.getRSSLink();
                                        if(typeof pglink != 'undefined'){
                                                checkNode.href = PG.getRSSLink();
                                                }
                                        }
                        }
                }
         },
         
        doAPRSSGet : function(parentElement, feedName, count){
                if (typeof parentElement != 'undefined'){
                        if(typeof PG.apfeed != 'undefined'){
 	                   
 	                     var feedUrl = PG.proxyURL + 'rssProxy.aspx?feedName=' + PG.apfeed[feedName].description + '&sectionTemplate=' + PG.apfeed[feedName].section;   
                       
                //              var feedUrl = 'approxy.php' + '?1requestID=' + PG.proxyRequestID.getAPRSS + '&1params=' + PG.apfeed[feedName].description + '&2params=' + PG.apfeed[feedName].section;
                       
                                var title = PG.apfeed[feedName].title;
                                new Ajax.Request(feedUrl , 
                                                {
                                                        method:'get', 
                                                        onSuccess:function(trans){
                                                                PG.populateRSSList(parentElement, trans, title, count, true);
                                                                }
                                                }
                                );
                        }
                } 
        },       
          

        doPGRSSGet : function (listSection, section, count){
                if (typeof listSection != 'undefined'){
                        new Ajax.Request('rssproxy.php?test=' + section, { method:'get', onSuccess:function(transport){PG.populateRSSList(listSection, transport, '', count);}});
//                      new Ajax.Request(section, { method:'get', onSuccess:function(transport){PG.populateRSSList(listSection, transport, '', count);}});
                }
        },       

        populateRSSList : function(parentElement, rssxml, title, count, stripped_header) {
                 var rssList = $(parentElement + '_list');
                 rssList.addClassName('news_feed_list');

                 parentElement = $(parentElement);
				parentElement.addClassName('news_list_box_1col');
				parentElement.removeClassName('section_lower_newslist');

                 try{
                         var rssEntries = XMLParse.xml2ObjArray (rssxml.responseXML, "item");
                         var rssChannelInfo = XMLParse.xml2ObjArray (rssxml.responseXML, "channel");
                 } catch(e){
                 }

                 var titleSection = $(parentElement.id + '_header');
				titleSection.removeClassName('section_lower_header');
				titleSection.addClassName('smBoxHeader');
				
				/*OKKER */
				
				titleSection.addClassName('news_list_header');

				
				if(stripped_header){
					//this is an AP feed so no links in the header
					
					
					titleSection.innerHTML = '';
					if(typeof title == 'undefined' || title == ''){
							if(rssChannelInfo.size() > 0){
									feedSectionLink.href = rssChannelInfo[0].link
									var correctedTitle = rssChannelInfo[0].title.substring(rssChannelInfo[0].title.lastIndexOf('-') + 2, rssChannelInfo [0].title.length);
									var feedTitle = document.createElement("span");
									feedTitle.innerHTML = correctedTitle + "&raquot;";
									titleSection.appendChild(feedTitle);
									}
					} else {
							var feedTitle = document.createElement("span");
							feedTitle.innerHTML = title;
							titleSection.appendChild(feedTitle);
					}

				
				} else {

					var feedLink = document.createElement("a");
					feedLink.href = rssxml.responseXML.baseURI;
					var feedIcon = document.createElement("img");
					feedIcon.alt = "";
					feedIcon.src = "/includes/2007design/images/icons/white/rss.png"
					feedLink.appendChild(feedIcon);
	
					var feedSectionLink = document.createElement("a");
					feedSectionLink.href = "/";
					titleSection.innerHTML = '';
	
					if(typeof title == 'undefined' || title == ''){
							if(rssChannelInfo.size() > 0){
									feedSectionLink.href = rssChannelInfo[0].link
									var correctedTitle = rssChannelInfo[0].title.substring(rssChannelInfo[0].title.lastIndexOf('-') + 2, rssChannelInfo [0].title.length);
									feedSectionLink.innerHTML = correctedTitle;
									}
					} else {
							feedSectionLink.innerHTML = title;
					}
	
					titleSection.appendChild(feedLink);
					titleSection.appendChild(feedSectionLink);

				}
				
                 if(typeof count == 'undefined'){
                         count = 5;
                 }


                 if(typeof rssList != 'undefined'){
                         //There is (for standards reasons, an empty li attached to each of these - remove it now

                         var nodeSearch = rssList.childNodes;
                         for(var n = 0; n < nodeSearch.length; n++){
                                 var testNode = nodeSearch[n];
                                 if(testNode.nodeType == 1 && testNode.tagName == 'LI'){
                                         rssList.removeChild(testNode);
                                 }

                         }


                         for(var i = 0; i < count && i < rssEntries.size(); i++){
                                 var rssItem = rssEntries[i];

                                 var rsslistitem = document.createElement("li");
                                 var rsslink = document.createElement ("a");

                                 var linkHref = rssItem.link;

                                 if(linkHref.lastIndexOf('hosted.ap.org') == -1 && linkHref.lastIndexOf('?') > -1){
                                         //remove the omniture hook
                                         linkHref = linkHref.substring (0, linkHref.lastIndexOf('?'));
                                 }

                                 rsslink.href = linkHref;
                                 rsslink.innerHTML = rssItem.title;

                                 rsslistitem.appendChild(rsslink);
                                 rssList.appendChild(rsslistitem);
                         }
                 }
         },



        populateRelatedList : function(parentElement, rssxml){
                var relatedList = $(parentElement);
                try{
                        var rssEntries = XMLParse.xml2ObjArray(rssxml.responseXML, "item");
                        var rssChannelInfo = XMLParse.xml2ObjArray(rssxml.responseXML, "channel");
                } catch(e){
                }


                if(typeof relatedList != 'undefined'){
                        for(var i = 0; i < 3 && i < rssEntries.size(); i++){


                                var rssItem = rssEntries[i];

                                var relatedItem = document.createElement("span");
                                var relatedLink = document.createElement("a");

                                relatedItem.className = 'story_link';

                                relatedLink.href = rssItem.link;
                                relatedLink.innerHTML = rssItem.title;

                                relatedItem.appendChild(relatedLink);
                                if(typeof rssChannelInfo != 'undefined'){
                                                var sectionLink = document.createElement("a");
                                                var sectionSpan = document.createElement("span");
                                                var correctedTitle = rssChannelInfo[0].title.substring(rssChannelInfo[0].title.lastIndexOf('-') + 2, rssChannelInfo[0].title.length);

                                                sectionLink.innerHTML = correctedTitle;
                                                sectionLink.href = rssChannelInfo[0].link;
                                                sectionSpan.className = 'small_section_marker';
                                                sectionSpan.appendChild(sectionLink);
                                                relatedList.appendChild(sectionSpan);
                                }
                                relatedList.appendChild(relatedItem);
                        }
                }
        },


        populateAdvertisements : function() {
                // JLF 20070823 - Old proxy; this one was replaced with adproxy.aspx.
                var endpointURL = PG.proxyURL + "?requestID=" + PG.proxyRequestID.getAdLocations + "&params=" + sitepage;
                //var endpointURL = PG.proxyURL + "default.asmx/GetAdvertisingPositions?strSitePage=" + sitepage;
                new Ajax.Request(endpointURL, { method:'get', onSuccess:PG.embedAdvertising});
        },

        embedAdvertising : function(adxml){

                try{
                        var adPlacement = XMLParse.xml2ObjArray(adxml.responseXML, "AdvPositions");
                } catch(e){
                }

                if(adPlacement.size() > 0){
                        var sitePage = adPlacement[0].SitePage;
                        var positionsUnsorted = adPlacement[0].Positions.split(',');
                        var positions = positionsUnsorted.sort();


                        //loop through the items returned and build the list
                        for(var i = 0; i < positions.size(); i++) {
                                var RN = new String(Math.random());
                                var RNS = RN.substring(2, 11);
                                var oas = "http://oascentral.post-gazette.com/RealMedia/ads/";
                                var oaspage = sitepage + "/1" + RNS + "@" + positions[i];
                                var endpointURL = oas + "adstream_sx.ads/" + oaspage;
                                var location = positions[i];
                                var elemId = '';
                                switch(location){

                                        case 'Top2' :
                                                new Ajax.Request('approxy.php?url='+endpointURL, { method:'get', onSuccess: function(adTransport){PG.DisplayOASAd('ad_top',  'Top2', adTransport);}});
                                                break;
                                        case 'Right1':
                                                new Ajax.Request('approxy.php?url='+endpointURL, { method:'get', onSuccess: function(adTransport){PG.DisplayOASAd('ad_right',  'Right1', adTransport);}});
                                                break;
                                        case 'Right':
                                                new Ajax.Request('approxy.php?url='+endpointURL, { method:'get', onSuccess: function(adTransport){PG.DisplayOASAd('ad_left',  'Right', adTransport);}});
                                                break;
                                        case 'Left':
                                                new Ajax.Request('approxy.php?url='+endpointURL, { method:'get', onSuccess: function(adTransport){PG.DisplayOASAd('ad_left',  'Left', adTransport);}});
                                                break;
                                        case 'Middle' :
                                                new Ajax.Request('approxy.php?url='+endpointURL, { method:'get', onSuccess: function(adTransport){PG.DisplayOASAd('ad_right',  'Middle', adTransport);}});
                                                break;
                                }

                        }
                }
         },

        inlineAdvertising : function(adSection){
                if(typeof adPositions != 'undefined' && adPositions != ""){

                        var sitePage = sitepage;
                var protocol = document.URL;
                protocol = protocol.substring(0, 5);
                var oas = '';
     
                if(protocol.lastIndexOf('s') == -1){ 
                        protocol = 'http://oascentral.post-gazette.com';
                } else {
                        protocol = 'https://oasc02.247realmedia.com';
                }
                        oas = protocol + "/RealMedia/ads/";
                        var RN = new String(Math.random());
                var RNS = RN.substring(2, 11);
                        var oaspage = sitepage + "/1" + RNS + "@";
                        var endpointURL = oas + "adstream_jx.ads/" + oaspage;

                        switch(adSection){

                                case 'ad_top':
                                        if(adPositions.indexOf('Top') > -1){
                                                var adloc = adPositions.substring(adPositions.indexOf('Top'), adPositions.length);
                                                if(adloc.indexOf(",") > -1){
                                                        adloc = adloc.substring(0, adloc.indexOf(","));
                                                }
                                                document.write('<div class="top_ad"><scri' + 'pt src="' + endpointURL + adloc + '" type="text/javascript"></script></div>');
                                        }
                                break;

                                case 'ad_right':
                                        var retVal = '';
                                        var ads = adPositions.split(',');

                                        for(var a = 0; a < ads.size(); a++){

                                                if(ads[a].indexOf('Top') > -1) continue;

                                                if(ads[a].indexOf('google') == 0){
                                                                retVal += '<div class="right_ad">' +
                                                                                        '<script type="text/javascript">' +
                                                                                        'google_ad_client = "pub-0320899052287117"; ' +
                                                                                        'google_ad_width = 160; ' +
                                                                                        'google_ad_height = 600; ' +
                                                                                        'google_ad_format = "160x600_as"; ' +
                                                                                        'google_ad_type = "text"; ' +
                                                                                        'google_ad_channel = ""; ' +
                                                                                        'google_color_border = "3B3B3B"; ' +
                                                                                        'google_color_bg = "FFFFFF"; ' +
                                                                                        'google_color_link = "3B3B3B"; ' + 
                                                                                        'google_color_text = "000000"; ' + 
                                                                                        'google_color_url = "3B3B3B"; ' + 
                                                                                        'google_ui_features = "rc:0"; ' +
                                                                                        '</script> ' +
                                                                                        '<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>' + 
                                                                                        '<div class="right_ad_hack"></div>' +
                                                                                        '</div>';

                                                } else {
                                                        retVal += '<div class="right_ad"><script src="' + endpointURL + ads[a] + '" type="text/javascript"></script></div>';
                                                }
                                        }
                                return retVal;
                                break;

                        }

                }
                return "";
         },
         
         retargetIframeLinks : function(iframeid){
         
         
         
         },
         
         DisplayOASAd : function (parentId, position, adxml) {

                var parent = document.getElementById(parentId);
                var container = document.createElement("div");

                if(typeof adxml.responseText != 'undefined'){
                        container.innerHTML = adxml.responseText;
                } else {
                                container.innerHTML = adxml;
                }

                if(position.indexOf("Right") > -1 || position.indexOf("Middle") > -1){
                        container.className = 'right_ad';
                        parent.appendChild(container);

                }

                if(position.indexOf("Left") > -1){
                        container.className = 'left_ad';
                        parent.appendChild(container);
                }

                if(position.indexOf("Top") > -1){
                        container.className = 'top_ad';
                parent.appendChild(container);

                }

        },

        OAS_AD : function(adName){
                // Used for one-off ads in places other than the rails.
                if(typeof adName != 'undefined'){
                        var sitePage = sitepage;
                        var protocol = document.URL;
                        protocol = protocol.substring(0, 5);
                        var oas = '';
                     
                        if(protocol.lastIndexOf('s') == -1){ 
                                protocol = 'http://oascentral.post-gazette.com';
                        } else {
                                protocol = 'https://oasc02.247realmedia.com';
                        }

                        oas = protocol + "/RealMedia/ads/";
                        var RN = new String(Math.random());
                        var RNS = RN.substring(2, 11);
                        var oaspage = sitepage + "/1" + RNS + "@";
                        var endpointURL = oas + "adstream_jx.ads/" + oaspage;

                        document.write('<div class="oas_compat_ad"><script src="' + endpointURL + adName + '" type="text/javascript"></script></div>');
                }
        },

        GoogleAd : function(){
                document.write('<script type="text/javascript">'
                        + 'google_ad_client = "pub-0320899052287117"; '
                        + 'google_ad_width = 160; '
                        + 'google_ad_height = 600; '
                        + 'google_ad_format = "160x600_as"; '
                        + 'google_ad_type = "text"; '
                        + 'google_ad_channel = ""; '
                        + 'google_color_border = "3B3B3B"; '
                        + 'google_color_bg = "FFFFFF"; '
                        + 'google_color_link = "3B3B3B"; '
                        + 'google_color_text = "000000"; '
                        + 'google_color_url = "3B3B3B"; '
                        + 'google_ui_features = "rc:0"; '
                        + '</script> '
                        + "<script type='text/javascript' src='http://pagead2.googlesyndication.com/pagead/show_ads.js'></script>");
        }, 

        CreateDRB : function() {
                var src = "http://a201.g.akamai.net/7/201/32539/v001/dmc.download.akamai.com/32539/pittsburgh/employment/300x250.swf";

                document.write("<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' "
                                        + "codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0' "
                                        + "width='300' "
                                        + "height='250' "
                                        + "id='endrb1'>"
                                        + "<param name='allowScriptAccess' value='always' />"
                                        + "<param name='movie' value='" + src + "' />"
                                        + "<param name='quality' value='high' />"
                                        + "<param name='menu' value='false' />"
                                        + "<embed src='" + src + "' "
                                        + "quality='high' "
                                        + "width='300' "
                                        + "height='250' "
                                        + "name='endrb1' "
                                        + "align='middle' "
                                        + "menu='false' "
                                        + "allowScriptAccess='always' "
                                        + "type='application/x-shockwave-flash' "
                                        + "pluginspage='http://www.macromedia.com/go/getflashplayer'> "
                                        + "</embed> "
                                        + "</object>");
        },
        
		weatherMap : [],
			
		setCurrentWeatherId : function (wid){
			for(var o = 0; o < PG.weatherMap.size(); o++){
					for(var i = 0; i < PG.weatherMap[o].weather_ids.size(); i++){
						if(PG.weatherMap[o].weather_ids[i] == wid){
		                	//$('header').setStyle({ backgroundImage : 'url(' +  PG.weatherMap[o].imagepath + ')'});						
						}
	                }
	         }	
		},
		
		
		getTextSizeCookie : function(){
					
				var text_cookie = PG.getCookie('pg_text_size');				
				
				if(text_cookie =="" || text_cookie==undefined){
				
					text_cookie = "normal";	
									
				}
				

				var type_size = document.getElementById(text_cookie);
								PG.changeTextSize(type_size);
		},
		
         changeTextSize : function(elem){
         	var size = elem.id;
			var bodyTags = document.getElementsByTagName("body");
			var bodyTag = $(bodyTags[0]);
						
         	switch(size){
         		case ("smaller"):
         			bodyTag.setStyle({"font-size":"95%"});        		
	        		break;

         		case ("normal"):
         			bodyTag.setStyle({"font-size":"medium"});        		
	        		break;

         		case ("larger"):
         			bodyTag.setStyle({"font-size":"120%"});        		
	        		break;
         		
         		default:
         			break;
         	}	
         	
         	PG.setCookie('pg_text_size',size,365);
         	
         },
         
		showLoaded : false,
		showLoading : false,
		initialImage : undefined,

		photoJournalBySection : function(sectionId, launchLink, loadMax){
				if(typeof loadMax == "undefined") loadMax = 100;
				launchLink = $(launchLink);
				var endpointURL = PG.proxyURL + 'photojournal.aspx?lngSectionID=' + sectionId + "&intMaxPhotoCount=" + loadMax;
				if(!this.showLoaded){
					if(this.showLoading == false){
						this.showLoading = true;
						new Ajax.Request(endpointURL, { method:'get',
								onSuccess:function(transport){
										var allImages = eval(transport.responseText);
										var container = $('slideshow_container');
										var slideShowContent = allImages;
										container.setStyle( {'display' : 'none'});
										for(var i = 0; i < slideShowContent.size(); i++){
											var imageLink = document.createElement('A');
											imageLink.href = 'http://www.post-gazette.com/' + slideShowContent[i].url;
											imageLink.rel = 'lightbox[' + sectionId + ']';
											imageLink.title = slideShowContent[i].photoCredit + "<br/>" + slideShowContent[i].photoCaption;
											imageLink.innerHTML = slideShowContent[i].title;
											container.appendChild(imageLink);
											if(i == 0) PG.initialImage = imageLink;
											
										}
										PG.showLoaded = true;
										myLightbox.updateImageList();
										myLightbox.start(PG.initialImage);
										PG.showLoading = false;
								}
						});
					}
				} else {
					myLightbox.start(this.initialImage);
				}
			},		
		    handleEventSearch : function(inputArea){
                	
                	if(inputArea.id == 'whatSearch' && inputArea.value=='pizza, park, bike, etc'){
	                	inputArea.value ='';
                	}
                	
                	if(inputArea.id == 'whereSearch' && inputArea.value=='address or city, state or zip'){
	                	inputArea.value ='';
                	}
                	
                	if(inputArea.id == 'whatSearch' && document.getElementById('whereSearch').value==''){
                		document.getElementById('whereSearch').value='address or city, state or zip';
                		}
					if(inputArea.id == 'whereSearch' && document.getElementById('whatSearch').value==''){
                		document.getElementById('whatSearch').value='pizza, park, bike, etc';
                		}
        },
        
        swapAddIconEventAdd : function (){


				$$('.mod_widget_header_badge img').each(function(addIcon) {	
                
                	     Event.stopObserving(addIcon,'mouseover', PG.swapAddIconOn);
				         Event.stopObserving(addIcon,'mouseout', PG.swapAddIconOff);
						 Event.stopObserving(addIcon, 'click', PG.showClickWidgetMenu);

                
                
		                Event.observe(addIcon,'mouseover', PG.swapAddIconOn);
        		        Event.observe(addIcon,'mouseout', PG.swapAddIconOff);
						Event.observe(addIcon, 'click', PG.showClickWidgetMenu);
                });

        },
        
        swapAddIconOn : function(event){
  						var element = Event.element(event);
  			        	element.src='/includes/2007design/images/icons/DownOn.png';
        	
        },
		swapAddIconOff : function(event){
				var element = Event.element(event);
	        	element.src='/includes/2007design/images/icons/DownOff.png';
        	
        },
        
           
   showClickWidgetMenu : function ( event ){
        	
        	 			//PG.cX = event.clientX; PG.cY = event.clientY;	        
        	var element = Event.element(event);


		    var xypos =  Position.cumulativeOffset(element);			
				PG.cX = xypos[0]-10;
				PG.cY = xypos[1]-10;
			        				
        	var elementId = "";
			var notfound = true;
			
			element.ancestors().each(function(ancestorElement){  	
        	  	if(ancestorElement.id!="" && notfound){        	  		
        	  		PG.widgetElement=ancestorElement.id;
        	  		notfound = false;
        	  	}
        	  });		

        	var widgetMenu =  document.getElementById("widgetMenu");
        	if(!widgetMenu){
	        	widgetMenu = document.createElement("div");
	        	widgetMenu.id = "widgetMenu";
	        	widgetMenu.style.display='none';
	        	document.body.appendChild(widgetMenu);	
	     
				Event.observe($(widgetMenu), 'mouseover' , function(){
					clearTimeout(PG.widgetMenuTimer);
				});
				


	        	Event.observe($(widgetMenu),'click', function(){	        		
	        		
	        		PG.HideContent("widgetMenu");
	        		
	        	});
        	}
        	

			
        widgetMenu.innerHTML = "";	
        
        
	    var widgetMenuUL = document.createElement("ul");    
	    var widgetMenuItem = document.createElement("li");
	    var csUserCookie = PG.getCookie('CSUser');

		
		
	if(csUserCookie !=undefined ){

		   
        if(window.location.pathname=="/"){
        
        	var removeLink = document.createElement('a');		
				removeLink.id ="widgetMenu_remove";
        	var removeText = document.createTextNode("Remove");        		
        		removeLink.appendChild(removeText);
        		widgetMenuItem.appendChild(removeLink); 
        		
        	var widgetRefreshItem = document.createElement("li");
        	var refreshLink = document.createElement('a');
        		refreshLink.id ="widgetMenu_refresh";
        		
        	var refreshText = document.createTextNode("Refresh this widget");
        		refreshLink.appendChild(refreshText);
        		widgetRefreshItem.appendChild(refreshLink);
        		widgetMenuUL.appendChild(widgetRefreshItem);
        		widgetMenuUL.appendChild(widgetMenuItem);
				widgetMenu.appendChild(widgetMenuUL);
				        	

        	Event.observe(document.getElementById('widgetMenu_refresh'),'click',PG.refreshWidget);
        	
        	Event.observe(document.getElementById('widgetMenu_refresh'), 'mouseover', PG.clearWidgetMenuTimer);

        	
			Event.observe(document.getElementById('widgetMenu_remove'),'click',PG.addRemoveWidget);
			
			Event.observe(document.getElementById('widgetMenu_remove'), 'mouseover', PG.clearWidgetMenuTimer);

					        				
        }else{
        	var addLink = document.createElement('a');
        		addLink.id = "widgetMenu_add";
        
        /*  TODO: Add code here that will check to see if this widget is already in the list
         * 	If it is... then we're going to remove it.
         */
         	
         	var addText = null;
        		
        	var PGwidgetList = PG.getCookie('CSWidgets');
        		
        		if(PGwidgetList.indexOf(PG.widgetElement) > -1 ){
        			 addText = document.createTextNode("Remove from homepage");
        		}else{
        			 addText = document.createTextNode("Add to homepage");
        		}
        		
        		
        		addLink.appendChild(addText);
        		widgetMenuItem.appendChild(addLink);
        		widgetMenuUL.appendChild(widgetMenuItem);
				widgetMenu.appendChild(widgetMenuUL);
				Event.observe(document.getElementById('widgetMenu_add'),'click',PG.addRemoveWidget);        								Event.observe(document.getElementById('widgetMenu_add'), 'mouseover', PG.clearWidgetMenuTimer);
					


        }
        
        }//If logged in..
        else{
          	var loginLink = document.createElement('a');		
				loginLink.id ="widgetMenu_login";
				loginLink.href="http://community.post-gazette.com/SignIn.aspx";
        	var loginText = document.createTextNode("Login");        		
        		loginLink.appendChild(loginText);
        		widgetMenuItem.appendChild(loginLink); 
        		widgetMenuUL.appendChild(widgetMenuItem);
				widgetMenu.appendChild(widgetMenuUL);
				widgetMenu.style.width="100px";
				widgetMenu.style.textAlign="center";
				Event.observe(document.getElementById('widgetMenu_login'), 'mouseover', PG.clearWidgetMenuTimer);		
				
				

        
        }
        	PG.ShowContent('widgetMenu'); 	        	  
        

        },

clearWidgetMenuTimer: function(){

	clearTimeout(PG.widgetMenuTimer);
},

refreshWidget: function (event){
				var elementId = PG.widgetElement;	       
	            var widgetList = PG.getWidgetList();
	            var widgets = widgetList.split(",");
	    		
	    	var replaceWidget =	document.getElementById(elementId);
	    			  				var datetmp = new Date();

			var widgetContainer = document.getElementById("con_"+elementId);
			
			
			
	    	var widgetSrc = "/includes/2007design/site/"+elementId+".html?jjk="+datetmp.getTime();		
			
			
			
	    new Ajax.Request(widgetSrc, {
		  method: 'get',
		  onSuccess: function(transport) {		  				
		  				widgetContainer.innerHTML = transport.responseText;
	  					PG.swapAddIconEventAdd();	
			new Effect.Highlight($(PG.widgetElement) ,
								{duration: .3, startColor: '#000000', endColor: '#999999'});
			}
 		});
 		
		return false;
},

addRemoveWidget: function(event){
	var elementId = PG.widgetElement;
	var widgetList = PG.getWidgetList();
	
	if(widgetList.indexOf(elementId) > -1){
		
		var widgetArray = widgetList.split(",");
			
		widgetList = widgetArray.without(elementId).toString();
		
		Effect.BlindUp(elementId, {duration: .3, afterFinish : function(obj){
			for(var i in obj.effects){
				if(obj.effects[i]['element'] == elementId){
					Element.remove(removeElement);
				}
 			}		
	}
	
	});
	
	}else{
		widgetList +=","+elementId;
	}
	
	
	PG.setCookie('CSWidgets',widgetList,365);
	
	var widgetSaveCall = PG.widgetSaveEndpoint + "?widgetList="+widgetList;
	
	new Ajax.Request(widgetSaveCall, {
			method: 'get',
			onSuccess: function(transport){
			
			}
		
			}); 
	
	
	return false;


},

removeWidget: function(event){
	var elementId = PG.widgetElement;	
	var removeElement = document.getElementById("con_"+elementId);


	Effect.BlindUp(elementId, {duration: .3, afterFinish : function(obj){
			for(var i in obj.effects){
				if(obj.effects[i]['element'] == elementId){
					Element.remove(removeElement);
				}
 			}		
	}
	
	});

	var widgetList = PG.getWidgetList();
	var widgets = widgetList.split(",");
	widgets = 	widgets.without(elementId);		
	PG.setCookie('CSWidgets',widgets.toString(),365);
	
	return false;
},

getWidgetList: function(){
	var ret = "";
	var x = PG.getCookie('CSWidgets');

	if (x) {
		ret = x;	
	}else{	
		ret = "weatherWidget,paLottery,movieWidget,obit_widget,hotPicksWidget,999102,postedPhotoWidget";
		//PG.setCookie('pgwidgetlist',ret,365);
	}
	return ret;

},
        
displayHomePageWidgets: function(){

	var widgetList = PG.getWidgetList();	
	var widgets = widgetList.split(",");
	var leftrail =   document.getElementById('leftrail');
	widgets.each(function(widget){
		var widget_container_id = "con_"+widget;
		var widgetContainer = document.createElement("div");
			widgetContainer.id = widget_container_id;
			leftrail.appendChild(widgetContainer);
		
		var widget_container_id = "con_"+widget;	
		var widgetSrc = "/includes/2007design/site/"+widget+".html";		
		
		new Ajax.Request(widgetSrc, {
		  method: 'get',
		  onSuccess: function(transport) {
				var widget_container = document.getElementById(widget_container_id);
					widget_container.innerHTML = transport.responseText;
  				}
		});
		
	});
},

setCookie: function(c_name,value,expiredays)
		{
			var exdate=new Date();
			exdate.setDate(exdate.getDate()+expiredays);
			document.cookie=c_name+ "=" +escape(value)+
			((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
			+";path=/"
			+( ( PG.domain ) ? ";domain=" + PG.domain : "" );
;
		},

getCookie: function(c_name)
			{
			if (document.cookie.length>0)
			  {
			  c_start=document.cookie.indexOf(c_name + "=");
			  if (c_start!=-1)
				{ 
				c_start=c_start + c_name.length+1; 
				c_end=document.cookie.indexOf(";",c_start);
				if (c_end==-1) c_end=document.cookie.length;
				return unescape(document.cookie.substring(c_start,c_end));
				} 
			  }
			return null;
			},

AssignPosition :function (d) {
	var leftSet = PG.cX + 5;
	var topSet = PG.cY +5;		
	d.style.left = leftSet + "px";
	d.style.top = topSet + "px";
},

HideContent: function(d) {
	if(d.length < 1) { return; }
//	document.getElementById(d).style.display = "none";
	
	new Effect.Fade($(d),{duration: .25});


},

		makeWideNewsPage : function() {
			// Hides the left rail and widens the newshole to 670px.
			$("leftrail").style.width = "0px";
			$("leftrail").style.display = "none";
			$("newshole").style.width = "670px";		
		},

ShowContent: function(d) {
	if(d.length < 1) { return; }
	

	var dd = document.getElementById(d);
	PG.AssignPosition(dd);
	//dd.style.display = "block";

	if(d =='widgetMenu'){
		Event.observe($(dd),'mouseout', function(){ 
			    var call = "PG.HideContent('widgetMenu')";
					if(PG.widgetMenuTimer != 0){
							PG.clearWidgetMenuTimer();		
					}
					
					PG.widgetMenuTimer = window.setTimeout(call,1000);

		});	
		
	Event.observe($(dd), 'mouseover', PG.clearWidgetMenuTimer);
		
	}	
	new Effect.Appear($(dd),{duration: .25});
	
	
	
}

});
        
PG.weatherMap.push({imagepath : '/includes/2007design/images/header_weather/1.png', weather_ids : [1,2,5,30,32,33,37]});
PG.weatherMap.push({imagepath : '/includes/2007design/images/header_weather/2.png', weather_ids : [3,4,34,35,36]});
PG.weatherMap.push({imagepath : '/includes/2007design/images/header_weather/3.png', weather_ids : [6,7,8,38]});
PG.weatherMap.push({imagepath : '/includes/2007design/images/header_weather/4.png', weather_ids : [19,20,21,22,23,24,25,26,29,31,43,44]});
PG.weatherMap.push({imagepath : '/includes/2007design/images/header_weather/5.png', weather_ids : [12,13,14,18,39,40,41]});
PG.weatherMap.push({imagepath : '/includes/2007design/images/header_weather/6.png', weather_ids : [15,16,17,42]});
PG.weatherMap.push({imagepath : '/includes/2007design/images/header_weather/8.png', weather_ids : [11]});




if (CS == undefined) var CS = {}; // Make sure the base namespace exists.

CS = Object.extend(CS, {
        Version: '1.0.0',
        csak : null,
		postId: 0,
		showAllState: 0,
		postCount: 1000,
		postSend: '/apps/pagedata/PostComment.aspx',
		postGet: '/apps/pagedata/GetComments.aspx',
		
				
		
	//	postSend: '/forums/PostComment.php',
	//	postGet: '/forums/GetComments.php',
		
		  setCookie: function(c_name,value,expiredays)
		{
			/*
			var exdate=new Date();
			domain = ".post-gazette.com";
			
			exdate.setDate(exdate.getDate()+expiredays);
			document.cookie=c_name+ "=" +escape(value)+
			//( ( domain ) ? ";domain=" + domain : "" ) +
			((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
			*/
		},

		 getCookie: function(c_name)
			{
			if (document.cookie.length>0)
			  {
			  c_start=document.cookie.indexOf(c_name + "=");
			  if (c_start!=-1)
				{ 
				c_start=c_start + c_name.length+1; 
				c_end=document.cookie.indexOf(";",c_start);
				if (c_end==-1) c_end=document.cookie.length;
				return unescape(document.cookie.substring(c_start,c_end));
				} 
			  }
			return "";
			},
			
			checkCookie: function(cookiename)
				{
				c_name=CS.getCookie(cookiename);
				if (c_name!=null && c_name!="")
				{
					//alert('Auth Key '+c_name+'!');
					CS.csak = c_name;
					
				//	CS.setCSCookie("CSUser",CS.csak, 30);
					
					return true;
				}
				else 
				{
				//c_name=prompt('Please enter Auth Key:',"");
				if (c_name!=null && c_name!="")
				{
					//CS.setCookie(cookiename,c_name,365);
					CS.csak = c_name;
					return true;
				} else{ 
					
					}
				}
		},


		setCSCookie : function(username, authkey){
				
				var myValue = authkey + ':' + username;
				
			//	CS.setCookie('CSUser',myValue,4);
				
        },
        

        csCallError : function (originalRequest) {
        	
			$('formPreview').innerHTML = originalRequest.responseText;
			//alert("Foo!");
			
        	//alert("Something went wrong");
              ////f.log("Somethign Went Wrong");

        
        },
        
        determineComments: function (){
        
        	//get thread Id
        	
        	//get Expiration Date

        	//run functions
        	
        	var threadId = CS.getStoryThreadId();
        	var expDate = CS.getStoryExpDate();
        		
        	if(threadId > -1){	
        		CS.generateCommentHtml();		
				
				CS.getPostList(threadId);	
				if(CS.notExpired(expDate)){
					CS.displayPostForm();
				}else{
					CS.displayDisabledForm();
				}	
			}
        
        },
        
        notExpired : function (expdate){
        		
        		if(expdate == undefined || expdate == ""){
        			return true;
        		}else{
		        	
		        	
		        	var daytime = expdate.split(" ");
		        	
		        	var ds = daytime[0].split("-");
		        	var ts = daytime[1].split(":");
		        	
		        	var expiredate = new Date(ds[0],ds[1],ds[2],ts[0],ts[1],ts[2],0);
		        	var today = new Date();
		        	
		        	if(today >= expiredate){
						return false;
						
		        	}else{
				
						return true;
					}

		        	
        		}
        		
        	
        	return true;
        
        },
        getStoryThreadId : function(){
                var metatags = document.getElementsByTagName('META');
                var i = 0;
                for(i = 0; i < metatags.length; i++){
                        if(metatags[i].name == 'commentThreadId'){
                                return  metatags[i].content;
                        }
                }
         
                return -1;
         
         },
         
         getStoryExpDate : function(){
                var metatags = document.getElementsByTagName('META');
                var i = 0;
                for(i = 0; i < metatags.length; i++){
                        if(metatags[i].name == 'commentExpDate'){
                                return  metatags[i].content;
                        }
                }
         
                return -1;
         
         },
        
        getPostList : function (threadId){
			
			CS.postId = threadId;
			var d = new Date();
			
            var pars = 'fout=' + d.getMilliseconds(); 
        //	pars = pars + '&threadId='+threadId;
        	
			//pars = pars + '&url=/api/forums.ashx/threads/'+threadId+'/posts';
			
			pars += '&threadId='+threadId;
			
			pars += '&pageSize='+CS.postCount;
			
			
        	
        	document.forms.replyForm.tid.value=threadId;	

        	var ajaxRequest = new Ajax.Request(CS.postGet,
        		{
        			method:'get',
        			parameters: pars,
//        			asynchronous: false,
        			onSuccess: CS.processPostList,
        			onFailure: CS.csCallError
        			});
        		
        		
        	//Probably should populate the form here
        	
        //	var form = $('replyForm');
        //	 form['tid'] = threadId;
        	
        	
           
        
        },
        
    
        processPostList : function (originalRequest){
          //  $('leftrail').innerHTML = "<PRE>"+originalRequest.responseText+"</PRE>";
        	CS.displayPostList(originalRequest.responseText);
        	
        
        },
        
        displayPostForm : function(){
        			
		if(CS.checkCookie('CSUser')){
		
				
			//	CS.getForumList();
				
				$('loginForm_div').setStyle({display: 'none'});
				$('replyForm_div').setStyle({display:'block'});
			
		
		}else{
				//document.write('Not Logged in');
				
				$('loginForm_div').setStyle({display:'block'});
				$('replyForm_div').setStyle({display: 'none'});
				
			}
        
        },
        
        displayDisabledForm: function(){
        	$('formPreview').innerHTML = "Commenting has expired for this story";
        	$('formPreview').setStyle({display:'block'});
        	
        
        },
        
        
        
        login: function(){
        		try{
        		var form = $('loginForm');
        		
        		var username = form['username'];
        		
        		var key = $F(form['password'])+':'+$F(form['username']);
        		
				//CS.setCookie('csak',key,365);

        		//alert($F(form['username']));
        		
        		CS.displayPostForm();
        		}catch(e){
        		
        			alert(e);
        		}

//        		var username = document.getElementById('
        	
        },
         
    submitComment : function () {
        
        
        	$('formPreview').innerHTML = "Sending...";
        	document.getElementById('loginForm_div').style.display = 'none';
			document.getElementById('replyForm_div').style.display = 'none';
			document.getElementById('formPreview').style.display = 'block';
        	
        	var form = $('replyForm');
        	
        	var myThreadId = $F(form['tid']);
        	
        	var myDate = new Date();
        	      
			 var postTitle = "Reader Comment for Thread:" + myThreadId;
        	 var postBody =  escape($F(form['commentReply']));
             var csak = CS.getCookie('csak');
        
        
        	var pars = 'threadID='+myThreadId+'&postTitle='+postTitle+'&postBody='+postBody;

        	
        	
        	var ajaxRequest = new Ajax.Request(CS.postSend,
        		{
        			method:'post',
        			parameters: pars,
        			onSuccess: CS.processPostSubmit,
        			onFailure: CS.csCallError
        			});
        			
      
        
        },
        
        processPostSubmit : function(response){

        	

        	var responseTxt = response.responseText;
        	
        	

        		
        			
        		//	$('formPreview').innerHTML = 'We Have txt';
        			
					 var doc = CS.getXmlDocument(responseTxt);
        			 var xmlDoc=doc.documentElement;        		
        			
        			 var myTagName = xmlDoc.tagName;

        		
        			if(myTagName == "ForumPost"){
        				$('formPreview').innerHTML = "Thank you for your comment. It should appear on the site shortly";
        			} else if(myTagName == "Error"){
        				
        				var errorType = xmlDoc.getElementsByTagName('Type')[0].firstChild.data;
        				var errorMsg =  xmlDoc.getElementsByTagName('Message')[0].firstChild.data;
   							
						$('formPreview').innerHTML = "We're sorry, we experienced an Error: " + errorType + " : " + errorMsg;
						
					}else{
				
						$('formPreview').innerHTML = "We're sorry, we experienced an Error...";
						
        			}		
 
				CS.getPostList(CS.postId);
				
        
        
        },
        
        /* Displays the Information about the Thread */
        show_all_comments : function(){
        	
        	CS.showAllState++;
        	
        	if(CS.showAllState % 2){

        	$('show_all_comments').innerHTML = "<a onClick='CS.show_all_comments();'>Show Only Last 10 Comments &raquo;</a>";
					 var hidden_con = $$('.post_container_hidden');
						hidden_con.each(function(comment) {	
								comment.setStyle({'display':'block'});
								});
        	
        	
        	}else{

        		$('show_all_comments').innerHTML = "<a onClick='CS.show_all_comments();'>Show All Comments &raquo;</a>";
	        	 var hidden_con = $$('.post_container_hidden');
						hidden_con.each(function(comment) {	
								comment.setStyle({'display' : 'none'});
										});
                }
        	
        	
        
        },
        
        displayPostList : function(text){
        	
        	 try{
        	 var doc = CS.getXmlDocument(text);
        	 var x=doc.documentElement;
			var postCount = x.getAttribute('TotalCount') - 1;
			
			var forumInfoStuff = x.getElementsByTagName('ForumInfo')[0];
			
		
				
				var forumId = 0;
				
			var forumId = forumInfoStuff.getAttribute('Id');			 
			 
			 
        	 var postList = x.getElementsByTagName('ForumPost');
			 var outputHTML = '';
        	 //  for(var r=1; r< postList.length; r++){
        	 var postCount = 0;
				for(var r=postList.length-1; r>0; r--){
							postCount++;
					    	var post = postList[r];
					    	var postId = 	post.getAttribute('Id');
//					    	var postSubject = post.getElementsByTagName('Subject')[0].firstChild.data;
					    	var postBody = post.getElementsByTagName('Body')[0].firstChild.data;
					    	
					    	var postDate = post.getElementsByTagName('Date')[0].firstChild.data;
					    	var postAuthor = post.getElementsByTagName('AuthorInfo')[0].getAttribute('DisplayName');					    	
					    
					    	var myDate = new Date();
					  
							
							
							var postDate = postDate.replace(/\-/g, "/").replace(/T/," ").replace(/\.\d*/,"");
						   	var mydatems = Date.parse(postDate);
						   	var myDate = new Date(mydatems);
						   	try{
							var myPostDate = formatDate(myDate,'MMM dd, yyyy h:mma' );
							}catch(e){
								
							}
							

						    
						 	if(postCount <=10){
						    outputHTML = outputHTML + 
						   		"<div class='post_container'>\n" + 
						   		"<div class='postDate'>" + myPostDate + "</div> \n" +
						   		"<div class='postAuthor'><img src='/includes/2007design/images/icons/white/comment.png'>" + postAuthor + "</div>\n" +
						   		"<div class='postBody'>" + postBody + "</div> \n" +
						   		  "<div class='postFlag'><img src='/includes/2007design/images/icons/white/alertsign.png'>"+
						   	    	"<a onClick='CS.flag("+forumId+","+postId+")'>Flag as Abuse</a>"+
						   	       "</div>\n" +
						   		"</div>\n";	
						   	}else{
						   	outputHTML = outputHTML + 
						   		"<div class='post_container_hidden'>\n" + 
						   		"<div class='postDate'>" + myPostDate + "</div> \n" +
						   		"<div class='postAuthor'><img src='/includes/2007design/images/icons/white/comment.png'>" + postAuthor + "</div>\n" +
						   		"<div class='postBody'>" + postBody + "</div> \n" +
						   		  "<div class='postFlag'><img src='/includes/2007design/images/icons/white/alertsign.png'>"+
						   	    	"<a onClick='CS.flag("+forumId+","+postId+")'>Flag as Abuse</a>"+
						   	       "</div>\n" +
						   		"</div>\n";	
						   		}
						   	
							    	//forumList
						}
						
					if(postCount > 10){
						outputHTML = outputHTML +
							"<div id='show_all_comments'><a onClick='CS.show_all_comments();'>Show All Comments &raquo;</a></div>";
						}
						
							$('listPosts').innerHTML = outputHTML;
        	
        	 				$('comment_count_head').innerHTML = postCount + " ";
        	 			
        	 			
		}catch(e){

			
		}	
        	 				
        	 
        },
        

        flag : function(forumId, postId){
        	window.location = 'http://community.post-gazette.com/forums/ReportAbuse.aspx?ForumID='+forumId+'&ReportPostID='+postId;
        },
        
        /*
        getForumThreads : function (forumId){
        
        			var pars = 'url=/api/forms.ashx/forms/';
        			
        			
        
        },
        */
        getXmlDocument : function (responseString){
        				
        				
        		if (window.ActiveXObject)
						{
						var doc=new ActiveXObject("Microsoft.XMLDOM");
							doc.async="false";
							doc.loadXML(responseString);
						}
						// code for Mozilla, Firefox, Opera, etc.
						else
						{
							var parser=new DOMParser();
							var doc=parser.parseFromString(responseString,"text/xml");
						}
        				
        				return doc;
        
        },
        
        
        displayFormList : function (responseString){

        		
			
				
						var doc = CS.getXmlDocument(responseString);	
						
						
						var x=doc.documentElement;
					
						
					    var forumList = x.getElementsByTagName('ForumList');
					    
					    
						var forums = x.getElementsByTagName('Forum');
					    
				
					    
					    var outputHTML = '';
					    
					    for(var r=0; r< forums.length; r++){
					    
					    	var forum = forums[r];
					    	var forumId = 	forum.getAttribute('Id');
					    	
					    	var forumName = forum.getElementsByTagName('Name')[0].firstChild.data;
						    outputHTML = outputHTML + 'Name: ' + forumName + ' :: ID : ' + forumId + '<br />';	    	

						}
					    
					    	$('forumList').innerHTML = "*"+outputHTML;
					    	
					    	
		
						//x.getElementByName		
			},
			
		clearContent : function ( obj) {
			   if(obj.value == 'Enter Your Comment here'){
			   
			   obj.value=''; 
			   }else{
			   }
			   

        	},
        	
generateCommentHtml : function (){
	var newsHole = document.getElementById('newshole');
	
	
	var sep = document.createElement('div');
		sep.className = "separator";
	
	
	var titleBar = document.createElement('div');
		titleBar.className = 'boxHeader';
		
		titleBar.innerHTML = "<div style='float:right; clear: none;'>" +
							 "Read our <a>Guide to Commenting</a>" +
							 "</div> Add a Comment";
							
	var loginForm_div = document.createElement("div");
		loginForm_div.id = "loginForm_div";
		loginForm_div.style.display="none";
		
		loginForm_div.innerHTML = "<a href='http://community.post-gazette.com/SignIn.aspx'>Login</a> | " + 
								  "<a href='http://community.post-gazette.com/CreateUser.aspx'>Create User Account</a>";
	
	var replyForm_div = document.createElement("div");
		replyForm_div.id = "replyForm_div";
		replyForm_div.style.display="none";
		
		replyForm_div.innerHTML = "<form id='replyForm'>"+	
					 "<textarea name='commentReply' rows='10' onClick='CS.clearContent(this);'>"+
					"Enter Your Comment here"+
					"</textarea>"+
					"<img src='/includes/2007design/images/formbuttons/submitcomment_up.png' "+ 
					"onClick='CS.submitComment();this.src=\"/includes/2007design/images/formbuttons/submitcomment_down.png\";'>"+
					"Read our  <a href='terms.html'>Terms of Use</a>"+ 
					"<input type='hidden' name='tid' value='' /> </form>";

	var formPreview = document.createElement("div");
		formPreview.id = "formPreview";
		formPreview.style.display = "none";
		
		formPreview.innerHTML = "Thank you for commenting, your comment will appear on the site shortly.";
					  
	
	var commentCount = document.createElement("div");
		commentCount.style.marginTop = "20px";
		commentCount.className = "boxHeader";
		commentCount.id = "commentCount_div";
		commentCount.innerHTML = "<span id='comment_count_head'> </span> Reader Comments";
		
	var listPosts = document.createElement("div");
		listPosts.id="listPosts";
		
		newsHole.appendChild(sep);
		newsHole.appendChild(titleBar);
		newsHole.appendChild(loginForm_div);		
		newsHole.appendChild(replyForm_div);
		newsHole.appendChild(formPreview);
		newsHole.appendChild(commentCount);
		newsHole.appendChild(listPosts);		
		
}
 
		});


// Atlas advertising functions.

// Atlas page ID value.

var atlasPageId = getAtlasRandomNumber();
function getAtlasRandomNumber() {
return Math.round(Math.random() * 10e8);

}

function displayAd(paramList) {

var adserver = "http://pgcom.adbureau.net";
var random = getAtlasRandomNumber();
document.write("<scr");
document.write("ipt src='" + adserver + "/jserver/acc_random=" + random + paramList + "/pageid=" + atlasPageId + "'>");
document.write("</scr");
document.write("ipt>");
}


