var curPath="/en_US/news/photos";
var measurementPrefix = "/en_US/photo/FanStar_";
var ratingId;
var ratingText="Rate this photo";
var curRatingText = "Current rating: ";
var photos = new Array();
var photosXML;
var loc = document.location.href;
var params = window.location.search;
var flvLoc = loc.split("/");
var flashCrossDomainFile = "http://" + flvLoc[2] + "/crossdomain.xml";
switch(true){
case loc.indexOf("en_US")>-1: lang="en_US"; break;
default: lang="en_US"; break;
}
var galleriesXML = "/" + lang + "/news/photos/galleries.xml";
var flashDebug=false;//true;//
//var showGallery = "Visible";//"Hidden";//Hidden, Visible - show or hide button to open gallery view
//var startupState = "Open Gallery";//"Load Album";//"Load Album", "Load Album Then Wait", and "Open Gallery"
var appWidth = 613;
var appHeight = 426;
var imageNo = 0;
var imageFile = "";
switch(true){
case loc.indexOf("players")>-1: ref="players"; showGallery = "Never";break;
case loc.indexOf("news")>-1: ref="news"; break;
default: ref="news"; break;
}
if(params != null && params != ""){
params = params.split("&");
for (x=0; x< params.length; x++) {
if (params[x].indexOf("xmlPage=") > -1)
xmlPage = params[x].substring(params[x].indexOf("=")+1);
if (params[x].indexOf("galleriesXML=") > -1)
galleriesXML = params[x].substring(params[x].indexOf("=")+1);
if (params[x].indexOf("imageNo=") > -1){
imageNo = params[x].substring(params[x].indexOf("=")+1);//0 or positive integer
}
if (params[x].indexOf("debug=") > -1){
flashDebug = true;
}
if (params[x].indexOf("imageFile=") > -1){
imageFile = params[x].substring(params[x].indexOf("=")+1);//string representing imageFile name
}
}
}
function writeGallery(){
$('#ratingsFunctions').css('display','none');
if (imageFile !=""){
showGallery = "Visible";//Hidden, Visible - show or hide button to open gallery view
startupState = "Load Album";
}
var flashvars = {
flashDebug: flashDebug,
lang: lang,
xmlPage: xmlPage,
galleriesXML: galleriesXML,
vShowGallery: showGallery,
startupState: startupState,
flashDebug: flashDebug,
imageNo: imageNo,
ref: ref,
flashCrossDomainFile: flashCrossDomainFile,
imageFile: imageFile
};
var params = {
menu: "false",
allowFullScreen: "true",
quality: "high",
bgcolor: "#000000",
allowScriptAccess: "always",
wmode: "Opaque",
align: "middle"
};
var attributes = {
id: "photoGallery",
name: "photoGallery"
};
swfobject.embedSWF("/usg/flash/gallery_0.swf", "photoGallery", appWidth, appHeight, "9.0.0", false, flashvars, params, attributes);
}
function setGalleryTitle(newTitle){
//alert("newTitle: " + newTitle);
}
function reportImageLoaded(imageURL){
//alert("imageURL: " + imageURL);
$('#ratingsFunctions').css('display','block');
$(document).ready(function(){
ratingId = imageURL;
if (ratingId != undefined) {
writeYourRating(ratingId);
var stars = $(photosXML).find('fan').find('rating[image='+imageURL+']').attr('rounded');
writeCurrentRating(stars);
}
});
}
//*****************************
// measurement function for gallery app
// @param lang - lang of app, "en_US", "fr_FR", etc...
// @param gallery - gallery id or "start" or "stop" (for slideshow)
// @param image - image id
//*****************************
function galleryMeasure(lang,gallery,image){
measureClick(gallery+'_'+image+'.html');
}
//***************************************************
// accept logging calls from flash and js
//***************************************************
function flashLog(type,message){
message = unescape(message);
if (flashDebug && log){
switch (type){
case "trace": log.trace(message); break;
case "debug": log.debug(message); break;
case "info": log.info(message); break;
case "warn": log.warn(message); break;
case "error": log.error(message); break;
case "fatal": log.fatal(message); break;
default: break;
}
}
}
function traceDebug(message){
flashLog("debug",message);
}
//*******************************
// Initialize log4javascript logger
//*******************************
function startLogging(){
log = log4javascript.getLogger("mylogger");
// Create a PopUpAppender with default options
var popUpAppender = new log4javascript.PopUpAppender();
// Change the desired configuration options
//popUpAppender.setFocusPopUp(true);
//popUpAppender.setNewestMessageAtTop(true);
// Add the appender to the logger
log.addAppender(popUpAppender);
// Test the logger
log.info("USGA PhotoGallery init");
window.focus();
}
//alert("flashDebug: " + flashDebug);
if (flashDebug){
var e = document.createElement("script");
e.src = "/usg/js/log4javascript.js";
e.type="text/javascript";
document.getElementsByTagName("head")[0].appendChild(e);
}
//*******************************
//***************************************************************************
//photo rating objects
//***************************************************************************/
function photo(){
this.image;
this.votes;
this.rating;
this.stars;
}
//***************************************************************************
//function to set the photo objects
//***************************************************************************/
function setPhotoObjects(xmlDoc){ 
$(xmlDoc).find("rating").each(function() {
photos[photos.length] = new photo();
photos[photos.length-1].rating = $(this).text();
photos[photos.length-1].image = $(this).attr('image');
photos[photos.length-1].votes = $(this).attr('count');
photos[photos.length-1].stars = $(this).attr('rounded');
});
return xmlDoc;
}
$.ajax({
url: '/en_US/xml/gen/photo_star_ratings.xml',
type: 'GET',
dataType: 'xml',
error: function(){
//alert('Error loading data');
},
success: function(xmlResp){
photosXML = setPhotoObjects(xmlResp);
}
});