// ---------------------------------------------------------//
// GET/SET THE URL HASH
// ---------------------------------------------------------//
 
function hashString(key)
{ 
	var value = null;
	if(hashStringArr[key])
	{
		value=hashStringArr[key];
	}
	return value;
}

hashStringArr = new Array();

function hashString_Parse()
{
	var query = window.location.hash.substring(1);
	var pairs = query.split("&");
	var mainQuery =  window.location.search.substring(1);
	var mainQueryPairs = mainQuery.split("&");
	
	
	
	/* from ? */
	for (var i=0;i<mainQueryPairs.length;i++)
	{
		var mPos = mainQueryPairs[i].indexOf("=");
		if(mPos >= 0){
			var argname = mainQueryPairs[i].substring(0,mPos);
			var value = mainQueryPairs[i].substring(mPos+1);
			hashStringArr[argname]=value;		
		}
		
	}
	
	/* from # */
	for (var i=0;i<pairs.length;i++)
	{
		var pos = pairs[i].indexOf('=');
		if (pos >= 0)
		{
			var argname = pairs[i].substring(0,pos);
			var value = pairs[i].substring(pos+1);
			hashStringArr[argname]=value;
		}
	}
	

}



/* Get the current query string */

hashString_Parse(); // Start the query string gathering
var urlPhoto = hashString("photo"); // Get the photoID.  second

if(!urlPhoto){
	urlPhoto = hashString("photoId"); // Get the photoID.  first
}

if(layoutType == "topTen"){// check for top10 listing
	var tTen = 1;	 // set top10 for rest of code
}else{
	var tTen = 0; // set top10 for rest of code
	var layoutType = "currentSport"; // set the current sport type
}


/* Set and keep the root url */
var topURL = window.location.href; // get the current url
if(topURL.indexOf("#") > -1){ // check to see if there is a ? with data
	var topURL = topURL.substring(0, topURL.indexOf("#")) //reset the url to the page url only
}


// ---------------------------------------------------------//
// BANNER REFRESHER (728X90) //
// ---------------------------------------------------------//

var bannerCheck = 0;  // set the initial variable for counting
function bannerRefresh(){
	if(bannerCheck != 0){
		var ban = document.getElementById('ad728x90');
		ban.src = ban.src;		
	}
	bannerCheck++;	
}

// ---------------------------------------------------------//
// SET PERMALINK AND ADDTHIS INFORMATION//
// ---------------------------------------------------------//
var fsAddthis_url; // add this url holder
var fsAddthis_title; // add this title holder
function setHash(loc){
	document.location.hash= loc; // set the new url
	var newTitle = dsPhotos.getCurrentRow(); //get the current media title
	document.title = newTitle['imageTitle']+" : FoxSports.com Photo Gallery"; // reset the HTML title bar	
	hashString_Parse(); // reset the parse...
	
	if(document.location.port){ // check if there's a location port
		var locPort = ":"+document.location.port; // set the location port
	}else{
		var locPort = '';
	}	
	
	fsAddthis_url = document.location.protocol+"//"+document.location.hostname+locPort+document.location.pathname+"?contentId="+urlContent+"&photoId="+newTitle['@id']; // create the "Add This" url
	fsAddthis_title  = newTitle['imageTitle']+" : FoxSports.com Photo Gallery"; // set the title for the add this
} 


// ---------------------------------------------------------//
// GET XML DATA //
// ---------------------------------------------------------//

var xmlMainLoc = "/photoGallery?contentId="+urlContent+"&type=main";
var xmlAllSportsLoc = "/photoGallery?type=allSports";
var xmlComments = "/widget/photogallery/comments";
fsHbxAutoRun = false; // bypass auto hbx call...  controlled by developer
 
var dsSport = new Spry.Data.XMLDataSet(xmlMainLoc, "category", {useCache:false});
var dsPhotoMain = new Spry.Data.XMLDataSet(xmlMainLoc, "category/gallery", {useCache:false}); // Get the XML Data
var dsPhotos = new Spry.Data.NestedXMLDataSet(dsPhotoMain, "media", {filterDataFunc:preLoadImages, useCache:false}); // Get the XML Data
var dsPhotoThumbs =  new Spry.Data.DataSet(); // Create Blank Dataset for Thumbnails

var dsEditorMain = new Spry.Data.XMLDataSet("/photoGallery?categoryId={dsSport::@id}&type=editor", "category/gallery", {subPaths: "media/thumbnail", useCache:false}); // Get the XML Data
var dsEditors = new Spry.Data.NestedXMLDataSet(dsEditorMain, "media", {useCache:false}); // Get the XML Data

var dsAllSportsMain =  new Spry.Data.XMLDataSet('/photoGallery?categoryId={dsSport::@id}&type=allSports', "galleries/category", {subPaths: "gallery/thumbnail", useCache:false});
var dsAllSportsGalleries = new Spry.Data.NestedXMLDataSet(dsAllSportsMain, "gallery", {useCache:false}); // Get the XML Data

var dsSportGalMain =  new Spry.Data.XMLDataSet('/photoGallery?categoryId={dsSport::@id}&type='+layoutType, "category/gallery", {subPaths: "media/thumbnail",useCache:false});
var dsSportGalleries = new Spry.Data.NestedXMLDataSet(dsSportGalMain, "media", {useCache:false}); // Get the XML Data

if(allowComments){ // check for comments
	var dsCommentsMain = new Spry.Data.XMLDataSet('', 'root/topic', {useCache:false});
	var dsCommentsPagination = new Spry.Data.XMLDataSet('', 'root/pagination', {useCache:false});
	var dsComments = new Spry.Data.NestedXMLDataSet(dsCommentsMain, "posts/post", {useCache:false}); // Get the XML Data
}

dsPhotos.sort('large','ascending');
dsPhotos.setColumnType('description','html'); // show the html in the descriptions
dsPhotos.setColumnType("thumbnail", "html"); // show the raw html
dsEditors.setColumnType("thumbnail", "html"); // show the raw html
dsAllSportsMain.setColumnType("gallery/thumbnail", "html"); // show the raw html
dsSportGalMain.setColumnType("media/thumbnail", "html"); // show the raw html
dsSportGalleries.setColumnType("thumbnail", "html"); // show the raw html
dsEditorMain.setColumnType("media/thumbnail", "html"); //show the raw html
function preLoadImages(ds, row, rowIndex){ // preload image function
	preLoadMe.load(row['large']); // preload the image	
	return row; // return the preloaded image
}

// ---------------------------------------------------------//
// GATHER THUMBNAILS AND PLACE THEM //
// ---------------------------------------------------------//
dsPhotos.addObserver({ onPostLoad: function() {
	dsPhotos.removeObserver(this);
	
	if(tTen == 0){
		
		/* Setup thumbnails */
		var thumbs =dsPhotos.getData(); 	
		var s=1;
		var arrt='';
		var set='[';
		for(i=0; i<thumbs.length; i++){
			if(thumbs[i]['thumbnail']){
				if(s<=1){
					arrt+='{'+"thumbnail_"+s+':"'+thumbs[i]['thumbnail']+'", id_'+s+':'+thumbs[i]["@id"]+',  ';			
				}if(s==5 || i==(thumbs.length-1)){		
					arrt += 'thumbnail_'+s+':"'+thumbs[i]['thumbnail']+'", id_'+s+':'+thumbs[i]["@id"]+' ';	
					
					arrt = arrt.substring(0,arrt.length-1);
					arrt+="},";					
					set +=arrt;	
					
					arrt='';
					s=0;	
					
				}else{
					arrt += 'thumbnail_'+s+':"'+thumbs[i]['thumbnail']+'", id_'+s+':'+thumbs[i]["@id"]+',  ';	
				}			
			}		
			s++;
		}
		
		set = set.substring(0,set.length-1)+"]";	
		dsPhotoThumbs.setDataFromArray(eval(set));
	
	}
	if(urlContent){ // load up the requested image
		var rowPhoto = dsPhotos.findRowsWithColumnValues({"@id": urlPhoto}, true, true); // search for the requested category	
		if(rowPhoto){
			dsPhotos.setCurrentRow(rowPhoto.ds_RowID);
		}
	}
	
	}
});


/* setup for the initial photos to load */
var observer = { onPostUpdate: function(notifier, data) { 
	Spry.Data.Region.removeObserver("counter", observer);
	if(urlPhoto){
		setTimeout("getPhoto('ini',{goToPhoto:urlPhoto})", 500);
		
	}else{
		getPhoto('ini',{goToPhoto:0}) 
	}	
	//setTimeout('Spry.Data.Region.removeObserver("counter", observer)', 700);
}};


// ---------------------------------------------------------//
// THUMBNAIL HTML PLACEMENTS //
// ---------------------------------------------------------//
// for gallery thumbnails //
Spry.Data.Region.addObserver("gallery_thumbnails", { onPostUpdate: function(){ // set observer for when the thumbnail achors get loaded
	var rows = dsPhotoThumbs.getData(); // get the thumbnails
	
	for (var i = 0; i < rows.length; i++){ // loop through the thumbnails
		var row = rows[i]; // get the rows
		var rid= row.ds_RowID; // get the individual rowId
		var t = document.getElementById("tn1_" + rid); // get the first thumbnail in the set
	   
		if (t) // checks to see if the thumbnail image actually exists in the markup
			t.src = row.thumbnail_1; // if so, then set the image source
		
		t = document.getElementById("tn2_" + rid); // get the second thumbnail in the set
		if (t) // checks to see if the thumbnail image actually exists in the markup
			t.src = row.thumbnail_2;// if so, then set the image source
		t = document.getElementById("tn3_" + rid);// get the third thumbnail in the set
		if (t) // checks to see if the thumbnail image actually exists in the markup
			t.src = row.thumbnail_3;// if so, then set the image source
		t = document.getElementById("tn4_" + rid);// get the fourth thumbnail in the set
		if (t) // checks to see if the thumbnail image actually exists in the markup							
			t.src = row.thumbnail_4;// if so, then set the image source
		t = document.getElementById("tn5_" + rid);// get the fifth thumbnail in the set
		 if (t)	 // checks to see if the thumbnail image actually exists in the markup						
			t.src = row.thumbnail_5;// if so, then set the image source
	} 

}});

// for Editors Galleries //
Spry.Data.Region.addObserver("editors_galleries", { onPostUpdate: function(){ // set observer for when the thumbnail achors get loaded
	var rows = dsEditorMain.getData(); // get the thumbnails
	
	for (var i = 0; i < rows.length; i++){ // loop through the thumbnails
		var row = rows[i]; // get the rows
		var rid= row.ds_RowID; // get the individual rowId
		var e = document.getElementById("e1_" + rid); // get the first thumbnail in the set

		if (e) // checks to see if the thumbnail image actually exists in the markup
			e.src = row['media/thumbnail']; // if so, then set the image source
		
		e = document.getElementById("e2_" + rid); // get the second thumbnail in the set
		if (e) // checks to see if the thumbnail image actually exists in the markup
			e.src = row['media/thumbnail'];// if so, then set the image source	
	} 

}});

// for Current Sport Galleries //
Spry.Data.Region.addObserver("other_galleries", { onPostUpdate: function(){ // set observer for when the thumbnail achors get loaded
	var rows = dsSportGalMain.getData(); // get the thumbnails

	for (var i = 0; i < rows.length; i++){ // loop through the thumbnails
		var row = rows[i]; // get the rows
		var rid= row.ds_RowID; // get the individual rowId
		var o = document.getElementById("o1_" + rid); // get the first thumbnail in the set
	
		if (o) // checks to see if the thumbnail image actually exists in the markup
			o.src = row['media/thumbnail']; // if so, then set the image source
		
		o = document.getElementById("o2_" + rid); // get the second thumbnail in the set
		if (o) // checks to see if the thumbnail image actually exists in the markup
			o.src = row['media/thumbnail'];// if so, then set the image source	
			
		o = document.getElementById("tt1_" + rid); // get the second thumbnail in the set
		if (o) // checks to see if the thumbnail image actually exists in the markup
			o.src = row['media/thumbnail'];// if so, then set the image source	
			
		o = document.getElementById("tt2_" + rid); // get the second thumbnail in the set
		if (o) // checks to see if the thumbnail image actually exists in the markup
			o.src = row['media/thumbnail'];// if so, then set the image source	
	} 
	
	var rows = dsAllSportsMain.getData(); // get the thumbnails

	for (var i = 0; i < rows.length; i++){ // loop through the thumbnails
		var row = rows[i]; // get the rows
		var rid= row.ds_RowID; // get the individual rowId
		var a = document.getElementById("a1_" + rid); // get the first thumbnail in the set
		
		if (a) // checks to see if the thumbnail image actually exists in the markup
			a.src = row['gallery/thumbnail']; // if so, then set the image source
		
		a = document.getElementById("a2_" + rid); // get the second thumbnail in the set
		if (a) // checks to see if the thumbnail image actually exists in the markup
			a.src = row['gallery/thumbnail'];// if so, then set the image source	
	} 
	

}});





// for Comments //
Spry.Data.Region.addObserver("user_comments", { onPostUpdate: function(){ // set observer for when the thumbnail achors get loaded
	var rows = dsComments.getData(); // get the thumbnails

	for (var i = 0; i < rows.length; i++){ // loop through the thumbnails
		var row = rows[i]; // get the rows
		var rid= row.ds_RowID; // get the individual rowId
		var o = document.getElementById("c0_" + rid); // get the first thumbnail in the set

		if (o) // checks to see if the thumbnail image actually exists in the markup
			o.src = row.avatarURLSmall; // if so, then set the image source
		
	} 

}});
 

// ---------------------------------------------------------//
// THUMBNAIL NAVIGATION //
// ---------------------------------------------------------//

function thumbNav(me, options){	
	var options = options || {};
	var direction = options.direction || null; // capture the selected direction
	var currentPanelIndex = sp2.getContentPanelIndex(sp2.getCurrentPanel()); // get the index of the current panel
	var panelPhoto;
	
	
	switch(direction){ // for directions
	case 'previous':  // previous	
		if(currentPanelIndex == 0){
			sp2.showLastPanel();	
		}else{
			sp2.showPreviousPanel();	
		}		
		break;
	case 'next': // next
		if((currentPanelIndex+1) == sp2.getContentPanelsCount()){
			sp2.showFirstPanel();	
		}else{
			sp2.showNextPanel();
		}	
		break;	
	case 'new': // new photos
		/* check for what group the selected image is in */
		if(dsPhotos.getCurrentRowID() < 0){
			panelPhoto = dsPhotos.getData().length-1;
		}else if(dsPhotos.getCurrentRowID() > (dsPhotos.getData().length-1)){
			panelPhoto = 0;	
		}else{
			panelPhoto = dsPhotos.getCurrentRowID();	
		}
		
		sp2.showPanel(Math.floor(panelPhoto/5)); // show the correct group of thumbnails
		break;
	}
	
}

// ---------------------------------------------------------//
// EXPAND GALLERIES //
// ---------------------------------------------------------//

function expandIt(me, content,size){
	
	me = document.getElementById(me);
	
	var con = document.getElementById(content); // content block
	if(tTen == 1){
		var exGal1 = document.getElementById('top10_other_gallery1');
		var button1 = document.getElementById('top10_editor_button1');
	}else{
		var exGal1 = document.getElementById('other_gallery1');
		var exGal2 = document.getElementById('other_gallery2');
		var button1 = document.getElementById('editor_button1');
		var button2 = document.getElementById('editor_button2');
	}
		
	if(navigator.appName.indexOf("Microsoft") == -1){ // for other browsers
		Spry.Effect.DoSlide(me.parentNode.id, {duration:500, from:"16px", to:size+"px", horizontal: true, toggle: true}); // slide effect
	}
	if(me.className == 'open'){// if it's open
		me.className=me.className+' close'; // close it up 
	
		if(content == 'ext_cont2'){
			if(exGal1.style.visibility == '' || exGal1.style.visibility == 'visible'){
				exGal1.style.visibility='hidden';
				button1.style.visibility = 'hidden';
			}
		}
		
		if(navigator.appName.indexOf("Microsoft") != -1){ // for IE		
			con.style.visibility="visible";	// show content block
			
		}
	}else{ // if it's closed
		me.className = 'open'; // open it up
		
		if(exGal1.style.visibility == 'hidden'){
			exGal1.style.visibility = 'visible';	
			button1.style.visibility = 'visible';
		}
		
		if(navigator.appName.indexOf("Microsoft") != -1){ // for IE
			con.style.visibility="hidden"; // hide content block
		}
	}

}

// ---------------------------------------------------------//
// ADVERTISEMENT REFRESH CODE //
// ---------------------------------------------------------//
function serveAdRefreshViaMSFT() {	
		dapMgr.trackEvent(eventType.click);	
}

// ---------------------------------------------------------//
// LOAD PHOTO //
// ---------------------------------------------------------//
var holderId;
var preLoadMe = new Spry.Utils.ImageLoader(); // preload the image
function getPhoto(me, options){
	
	try{
		
		var options = options || {};
		var goToPhoto = options.goToPhoto || 0;		
		var updateThumbnails = options.updateThumbnails || false;
		var id = options.id || null;
		var rowMea;
		var media;
						
		
		if(holderId){ // check for the previous thumbnail if any
			holderId.className = holderId.className.replace("on",""); // clear the "on" class in the previous thumbnail
		}
		 
		if (me.id){ // check to see if there is a click on the page...
			if(me.id == 'prev' || me.id == 'next' || me.id.indexOf("t_") == 0 || me.id =='main_image' ){
				cycleOff(); // clear the cycle if any
			}
			
		}
		
		/* check to see if it's the previous or next calling the change */
		if(goToPhoto == 'prev'){		
			goToPhoto = dsPhotos.getCurrentRowID();
			if(tTen == 1){ // check for top10 reverse order
				media = goToPhoto+1;
			}else{
				media = goToPhoto-1;		
			}
		}else if(goToPhoto == 'next'){
			goToPhoto = dsPhotos.getCurrentRowID();		
			if(tTen == 1){  // check for top10 reverse order
				media = goToPhoto-1;
			}else{
				media = goToPhoto+1;		
			}
		}else{
			if(tTen == 1 && goToPhoto == 0){
				var rc = dsPhotos.getRowCount(true)-1;
				rowMea = dsPhotos.getRowByRowNumber(rc, true); // search for the requested image
			}else{
				rowMea = dsPhotos.findRowsWithColumnValues({"@id": goToPhoto}, true, true); // search for the requested image
			}
		}
		
		/* adjust the counts for the prev/next calls */
		if(media || media == 0){
			if(media == 0){
				dsPhotos.setCurrentRow(0); // go to the selected photo	
			}else if(media < 0){
				dsPhotos.setCurrentRow(dsPhotos.getData().length-1); // go to the selected photo	
		
			}else if(media > (dsPhotos.getData().length-1) ){
				
				dsPhotos.setCurrentRow(0); // go to the selected photo
			}else{
				dsPhotos.setCurrentRow(media); // go to the selected photo		
				
			}
				rowMea = dsPhotos.getCurrentRow();		
			
		}
		
		/* actions for direct calls */
		if(rowMea){		
			dsPhotos.setCurrentRow(rowMea.ds_RowID); // go to the selected photo
			if(tTen == 0){ /* check for top 10 */
				document.getElementById("t_"+rowMea['@id']).className += "on"; // highlight the selected thumbnail
				holderId = document.getElementById("t_"+rowMea['@id']);	// store the selected thumbnails for later
			}
		}
			
		thumbNav('', {direction:'new'})// show the photo group...
		setHash("sport="+dsPhotos.getCurrentRow()['league']+"&photo="+dsPhotos.getCurrentRow()['@id']); // set the url information
		setTimeout("updateMainImage()", 50); // load the main image IE6 BUG FIX... use for all browsers though.
				
		if(tTen == 1){ // set page types
			var pageType = 'lists'; // lists/top10
		}else{
			var pageType = 'pgstories';	// regular galleries
		}
				
		if(me != 'ini'){ // check for initial page load				
			Spry.Utils.loadURL("GET", "/fe/xml/photo_gallery_pageview_candidate.xml?comscorekw=pageview_candidate&sport="+dsPhotos.getCurrentRow()['league']+"&photo="+dsPhotos.getCurrentRow()['@id']+"&ran="+Math.round((Math.random() * 10000) + 1), true); // call comscore				
			Spry.Utils.loadURL("GET", "/fe/html/photo_gallery/random.html", true); // call neilson			
			_hbPageView(dsPhotos.getCurrentRow()['league']+" : "+dsPhotos.getCurrentRow()['imageTitle']+" : FoxSports.com Photo Gallery",_hbxStrip(dsPhotos.getCurrentRow()['hitboxPath'].toLowerCase()+"/"+pageType+"/"+dsPhotoMain.getCurrentRow()['galleryTitle']+"/"+dsPhotos.getCurrentRow()['@id']+" - "+dsPhotos.getCurrentRow()['imageTitle'])); // hitbox call 
			serveAdRefreshViaMSFT(); // refresh the ads...			
			
							
		}else{	
			dapMgr.enableACB('ad300x250box',false); // enable advertisement
			dapMgr.renderAd('ad300x250box', adCode300x250, 300, 250); // render advertisement
			dapMgr.enableACB('ad728x90box',false); // enable advertisement
			dapMgr.renderAd('ad728x90box', adCode728x90, 728, 90);	 // render advertisement			
			
			if(fsHbxAutoRun == false){ // only run when auto run is off.			
				fsHbxPageName = dsPhotos.getCurrentRow()['league']+" : "+dsPhotos.getCurrentRow()['imageTitle']; // set hitbox page name
				fsHbxTrackingPath = _hbxStrip(dsPhotos.getCurrentRow()['hitboxPath'].toLowerCase()+"/"+pageType+"/"+dsPhotoMain.getCurrentRow()['galleryTitle']+"/"+dsPhotos.getCurrentRow()['@id']+" - "+dsPhotos.getCurrentRow()['imageTitle']); // set hitbox tracking path
				launchFsHbx(); // launch hitbox
			}
		}
		
		
		
		/* check to see if the auto run is on */
		if(autoRun){
			cycleOn(cycler,cycleTime);		
		}else{
			cycleOff(); // clear the cycle if any	
		}
		
		if(allowComments){ // check for comments
			setTimeout("pageComments('', 1)", 700); // load in the new comments 
		}
		
			
	}catch(e){alert('Get Photo Error: '+e.message);}
}

function updateMainImage(){
	/* Update Main Image */
		var mainImgInfo = dsPhotos.getCurrentRow();
		document.getElementById("main_img").src = mainImgInfo['large']; // update main image
		document.getElementById("main_img").alt = mainImgInfo['imageTitle']; // update main image
		document.getElementById("main_img").title = mainImgInfo['imageTitle']; // update main image title
}	


// ---------------------------------------------------------//
// AUTO RUN //
// ---------------------------------------------------------//
var autoRun; // auto run holder
var cycleTime; // cycle time holder
var cycler=''; // cycler holder
function cycleOn(me, count){

	if(me.id == 'play_pause'){		
		me.onclick = function(){cycleOff()}; // set the onlclick for the play/pause button	
		var me = document.getElementById('cycle3'); // set the default cycle
	}
	
	/* check for a new time */
	if(me != cycler && cycler != ''){
		cycleOff();
	}
	
	/* Check for any bogus entries */
	if(count != 3000 && count != 6000 && count != 9000 && count != 12000){
		count = 3000; // set a default time
	
	}
	
	cycler = me; // holder for the cycler
	cycleTime = count; // holder for the time
	cycler.className = "on"; // turn the current cycler on
	
	autoRun = setTimeout("getPhoto('', {goToPhoto: 'next'})",cycleTime); // cycle through the photos
	document.getElementById('play_pause').className = "pause"; // change the play/pause button
	document.getElementById('play_pause').onclick = function(){cycleOff()};	// set the onlclick for the play/pause button
	document.getElementById('playing_image').className = "on"; // turn on the rotating image.
}
function cycleOff(){
	if(autoRun){ // check to see if it's auto running
		clearTimeout(autoRun);  // clear the current timer	
		cycler.className = ""; // turn off the current cycler
		document.getElementById('play_pause').className = ""; // change the play/pause button
		document.getElementById('playing_image').className = ""; // turn off the rotating image.
		document.getElementById('play_pause').onclick = function(){cycleOn(this,3000)};	// set the onlclick for the play/pause button	
		autoRun='';
		cycleTime=''; // cycle time holder
		cycler=''; // cycler holder
	}
}

// ---------------------------------------------------------//
// COMMENTS //
// ---------------------------------------------------------//

function addComments(){	// Add Comments Expander
	Spry.Effect.DoSlide('add_comments', {duration:300, from:"0px", to:"100%", toggle:true});
	
}

function pageComments(me, showPage){ // Page through comments
	dsCommentsMain.setURL(xmlComments+'?contentId='+dsPhotos.getCurrentRow()['@id']+'&page_no='+showPage); // set the url	
	dsCommentsMain.loadData(); // load in the new comments  
	
	dsCommentsPagination.setURL(xmlComments+'?contentId='+dsPhotos.getCurrentRow()['@id']+'&page_no='+showPage); // set the url
	dsCommentsPagination.loadData(); // load in the new pagination set  
}

function postComments(me){ // Post a comment
	
	var newComment = encodeURI(document.forms['comm'].comment2add.value); // get the comments
	var photoId =  dsPhotos.getCurrentRow()['@id']; // get the photo Id
	var userId = uid; // get the users ID
	
	var req = Spry.Utils.loadURL("GET", "/widget/photogallery/addComments?userId="+userId+"&photoId="+photoId+"&comment="+newComment, true, runComments); // send the comments (loadComments) is going to run when we get a response back
	
} 

function reportMe(tid, pid){ // Report a comment
	var url = "http://community.foxsports.com/boards/report.aspx?topic_id=" + tid.toString() + "&post_id=" + pid.toString();	
	var reportIt = window.open(url, 'popwin', "width=500, height = 400 ,menubar=no,status=no,location=no,toolbar=no,scrollbars=no");
	reportIt.focus();
}

function runComments(req){	// Reload comments AFTER a new one has posted
	if(req){ // check if this is a response call
		var text = req.xhRequest.responseText; // get the response text
		if(text){ // if there is text
			document.comm.comment2add.value = '';	// clear the value of the comment field		
			Spry.Effect.DoSlide('add_comments', {duration:300, from:"0px", to:"100%", toggle:true}); // to close up the comments			 
			
			dsCommentsMain.setURL(xmlComments+'?contentId='+dsPhotos.getCurrentRow()['@id']+'&ran='+Math.round((Math.random() * 10000) + 1));
			setTimeout("dsCommentsMain.loadData()", 300);
		}
	}	
}
