document.write('<script src="/my_php/Json/json.js" type="text/javascript"></script>');
document.write('<script src="/my_php/Json/json2.js" type="text/javascript"></script>');
document.write('<script src="/my_php/Frankfeet/html.js" type="text/javascript"></script>');

var comments = {
	aData: {},
	sId: '',
	doList: function() {
		var sAccordion = '', sHeader = '', sLink = '';
		$.each( comments.aData, function() { 
			sName = ff.doTag( {sTag:'span',sText:this.name,sClass:'comment_poster'} );
			sLink = ff.doLink( {sHref:'#',sText:sName+' says: '+this.title} );
			sHeader = ff.doTag( {sTag:'h3',sText:sLink} );
			sHeader += ff.doDiv( {sText:this.comment,sClass:"comment_text"} );
			sHeader = ff.doDiv( {sText:sHeader} );
			sAccordion += sHeader;
		});
		if ( comments.aData.length==0 ) {
			sAccordion = '<div style="text-align:center; font-size:18px;">There are no comments yet. Add your own and be the first!</div>';
		}
		return sAccordion;
	},
	doRefresh: function( oContainer, oButton, active ) {
		opts = $.extend({active: false}, {active:active} );
		frankfeet.doAjaxStart( { displaying:'comments' },
			function ( data ) {
				comments.aData = data;
				oContainer.accordion('destroy');
				oContainer.html( comments.doList() );
				oContainer.accordion({ header: "h3", fillspace:false, collapsible: true, active:opts.active, autoHeight:true });
				comments.doDialog();
				oButton.click(function() { $('#dialog').dialog('open'); });
			}
		);
	},
	doDialog: function() { 
		$("#dialog").dialog( {bgiframe: true, autoOpen: false, width:700, modal: true,
			buttons: { 
				'Post now': function() { 
					if ( $("#ff_FormName").val() == "" ) { $("#form_error").html("Please fill in your NAME!"); }
					else if ( $("#ff_FormName").val().length > 20 ) { $("#form_error").html("Your name must be less than 20 characters!"); }
					else if ( $("#ff_FormEmail").val().length > 30 ) { $("#form_error").html("Your email must be less than 30 characters!"); }
					else if ( $("#ff_FormTitle").val() == "" ) { $("#form_error").html("Please fill in a TITLE!"); }
					else if ( $("#ff_FormTitle").val().length > 50 ) { $("#form_error").html("The title must be less than 50 characters!"); }
					else if ( $("#ff_FormComment").val() == "" ) { $("#form_error").html("What would a comment be without a comment? Hello??"); }
					else {
						var temp = {};
						temp["name"] = $("#ff_FormName").val();
						temp["email"] = $("#ff_FormEmail").val();
						temp["title"] = $("#ff_FormTitle").val();
						temp["comment"] = $("#ff_FormComment").val();
						temp["ipaddress"] = frankfeet.ipAddress;
						var theData = { collection: frankfeet.collection, gallerypos: frankfeet.gallery_pos, comment_id:comments.sId, insert:'comments', pagester:'galleries.js', tammysammy:'misterdisfiggy', very_fast_data:JSON.encode(temp), t:Math.floor(Math.random()) };
						$.ajax({
							type: "GET",
							url: "/my_php/Frankfeet/ajax-galleries-data.php",
							cache: false,
							data: theData,
							datatype: 'json',
							success: function(data2) {
								var temps=JSON.parse(data2); 
								if ( temps['result']=="VeryGood" ) { 
									comments.doRefresh( $('#ff_accordion'), $("#add_Comments"), 0 );
									$("#ff_success").html('Your comment was posted successfully!');
									$("#dialog").dialog('close');
								} else {
									alert('Error with comment database. Don\'t know why. Try again in a few minutes.');
									$("#dialog").dialog('close');
								}
							},
							error: function() {
								alert('Error with comment database. Don\'t know why. Try again in a few minutes.');
								$("#dialog").dialog('close');
							}
						});
					}
				},
				'Cancel': function() { $(this).dialog('close'); }
			},
			close: function() {
				$("#form_error").html('');
				$("#ff_FormName").val('');
				$("#ff_FormEmail").val('');
				$("#ff_FormTitle").val('');
				$("#ff_FormComment").val('');
			}
		} );
	},
	FILLER: null
};
var frankfeet = {
	init: false,
	ipAddress: '',
	aPictures: {},
	aGallery: {},
	aComments: {},
	aBanners: [],
	iPictureId: -1,
	iScrollTop: -1,
	collection: '',
	gallery_pos: 0,
	showDiv: function( divname ) { $(divname).css('display', 'block'); },
	hideDiv: function( divname ) { $(divname).css('display', 'none'); },
	getTitle: function() { return frankfeet.aGallery['gallery_title']; },
	getDescription: function() { return frankfeet.aGallery['description']; },
	getQuality: function() { return frankfeet.aGallery['quality']; },
	resizePage: function () {
		var h_document = $(window).height();
		var h_header = $('#ff_header_container').height();
		var new_height = (h_document - h_header)>300 ? (h_document - h_header) : 300;
		$('#ff_middle_container').css( {height: new_height - 4} );
		$('#ff_content_container').css( {height: new_height - 4 - 4} );
	},
	video_html: function ( aSettings ) {
		$.extend({sFilename: null,sDivName: null,iWidth: null,iHeight: null}, aSettings );
		var bError=false;
		for ( var key in aSettings ) { bError=((bError) ? true : aSettings[key]==null);}
		if (!bError) {
			var sFull_Filename=''; 
			if (aSettings.sFilename!='') { sFull_Filename = 'http://www.frankfeet.com/'+aSettings.sFilename+'&autostart=true'; }
			sReturn = '<scr'+'ipt type="text/javascript" src="https://media.dreamhost.com/swfobject.js"></scr'+'ipt>';
			sReturn += '<div id="'+aSettings.sDivName+'" style="display:none;"><a href="http://www.macromedia.com/go/getflashplayer">Get';
			sReturn += ' the Flash Player</a> to see this player.</div>';
			sReturn += '<sc'+'ript type="text/javascript">';
			sReturn += 'var so = new SWFObject("https://media.dreamhost.com/mediaplayer.swf","mpl"';
			sReturn += ',"'+aSettings.iWidth+'","'+aSettings.iHeight+'","8");';
			sReturn += 'so.addParam("allowscriptaccess","always");';
			sReturn += 'so.addParam("allowfullscreen","true");';
			sReturn += 'so.addVariable("width","'+aSettings.iWidth+'");';
			sReturn += 'so.addVariable("height","'+aSettings.iHeight+'");';
			sReturn += 'so.addVariable("file","'+sFull_Filename+'");';
			sReturn += 'so.write("'+aSettings.sDivName+'");';
			sReturn += '</scr'+'ipt><br>';
			return sReturn;
		}
	},
	scroller_List: function() {
		sRet = '';
		$.each( frankfeet.aPictures, function() {
			sPicture = ff.doPicture( {sSrc:'/'+this['thumbnail_dir']+this['filename']} );
			sRet += sPicture;
		});
		return sRet;
	},
	process_Data: function( doing ) {  
		var sRet = '', sVideo='', sDownload='';
		if ( doing == 'story' || doing == 'description' || doing == 'gallery' ) { 
			sRet = ff.doDiv( {sText: ' ', sId:'banner_1', sClass:'content_banner'} );
			$.each( frankfeet.aPictures, function() {
				sPicture = ff.doPicture( {sSrc:'/'+this['thumbnail_dir']+this['filename']} );
				sRel = 'address:/picture_display_'+this['id'];
				sPicture = ff.doLink( {sHref:'javascript:void(0)',sText:sPicture,sRel:sRel} );
				sGallery = ff.doDiv( {sText: sPicture, sClass:'thumbnail-gallery'} );
				if (doing != 'gallery') {
					thisKey = (doing == 'story') ? 'story' : 'description';
					sGallery += ff.doDiv( {sText: this[thisKey], sClass:'story'} );
					sRet += ff.doDiv( {sText: sGallery, sClass:'gallery-container'} );
				} else sRet += sGallery;
			});
			sRet += ff.doDiv( {sText: ' ', sClass:'clearing'} );
			sRet += ff.doDiv( {sText: ' ', sId:'banner_2', sClass:'content_banner'} );
		} else if ( doing == 'first_page' ) {
			sRet = $('#ff_First_Page').html();
		} else if ( doing.search(/^picture_display_/) != -1 ) {
				frankfeet.iPictureId = doing.replace(/^picture_display_/,'');
				comments.sId = "picture_" + frankfeet.iPictureId;
				var index = 0;
				var idFound = -1;
				do {
					if ( frankfeet.aPictures[index]['id'] == frankfeet.iPictureId ) { idFound=index; }
					index += 1;
				} while ( idFound==-1 && index < frankfeet.aPictures.length );
				if (idFound != -1) {
					sPicture = ff.doPicture( {sSrc:'/'+frankfeet.aPictures[idFound]['fullsize_dir']+frankfeet.aPictures[idFound]['filename']} );
					sPicture += ff.doDiv( {sId:'ff_comments', sText:'Comments'} );
					sButton = ff.doInput( {sType:'button', sId:'add_Comments', sValue:'Add Your Comment'} );
					sPicture += ff.doDiv( {sId:'ff_success', sText:sButton} );
					sPicture += ff.doDiv( {sId:'ff_accordion', sText:' '} );
					sRet = sPicture;
				}
		} else if ( doing.search(/slideshow/) != -1 ) { //alert(frankfeet.aGallery[doing]);
			sButton = ff.doLink( {sHref:'javascript:void(0)',sName:'slideshow_story',sText:'Story Slideshow',sOnClick:'frankfeet.doThis(this.name)'} );
			sRet += ff.doTag( {sTag:'li',sText:sButton} );
			sButton = ff.doLink( {sHref:'javascript:void(0)',sName:'slideshow_masturbate',sText:'Masturbation Slideshow',sOnClick:'frankfeet.doThis(this.name);'} );
			sRet += ff.doTag( {sTag:'li',sText:sButton} );
			sButton = ff.doLink( {sHref:'javascript:void(0)',sName:'slideshow_slave',sText:'Slave Slideshow',sOnClick:'frankfeet.doThis(this.name);'} );
			sRet += ff.doTag( {sTag:'li',sText:sButton} );
			sRet = ff.doDiv( {sId:'ff_ContentMenu',sClass:'ddsmoothmenu',sText:ff.doTag( {sTag:'ul',sText:sRet} )} );
			var sFilename = (doing=='video_slideshow') ? "" : frankfeet.aGallery[doing];
			sVideo = frankfeet.video_html( {sFilename:sFilename, sDivName:"videodiv", iWidth:640, iHeight:480} );
			if ( (doing != 'video_slideshow') && sFilename=="") {
				sVideo = "<h2><b>This slideshow does not exist yet. Check back later. Sorry.</b></h2><br><br>";
			} else if (doing != 'video_slideshow') { 
				sDownload = ff.doLink( {sHref:'/'+frankfeet.aGallery[doing],sText:'Download this video here'} );
			}
			sRet += ff.doDiv( {sId:'ff_VideoPlayer',sText:sVideo + sDownload} ) ;
			sRet += ff.doDiv( {sText: ' ', sId:'banner_2', sClass:'content_banner'} );
		}
		return sRet;
	},
	display_Data: function( todisplay ) {
		comments.sId = 'gallery_'+frankfeet.aGallery['gallery_id'];
		sRet_Data = frankfeet.process_Data( todisplay )
		frankfeet.hideDiv('#ff_content');
		$("#ff_accordion").accordion('destroy');
		$('#ff_content').empty();
		$('#ff_content').append( sRet_Data );
		frankfeet.showDiv('#ff_content');
		if (todisplay=="first_page") { 
			$('#ff_left_scroller').append(frankfeet.scroller_List());
			$('#ff_left_scroller').imageScroller( {loading:'Wait please...',speed:'1500'} );
			comments.doRefresh( $('#ff_accordion'), $("#add_Comments") );
		} else if ( todisplay.search(/^picture_display_/) != -1 ) {
			comments.doRefresh( $('#ff_accordion'), $("#add_Comments") );
		} else if ( todisplay.search(/^slideshow/) != -1 ) {
			if (todisplay != 'video_slideshow') { $('#videodiv').css('display', 'block'); }
			if ($('#ff_ContentMenu').is('*')) {
				ddsmoothmenu.init({
					mainmenuid: 'ff_ContentMenu', //Menu DIV id
					orientation: 'h', //Horizontal or vertical menu: Set to "h" or "v"
					classname: 'ddsmoothmenu', //class added to menu's outer DIV
					customtheme: ['#993300', '#000000'],
					contentsource: 'markup' //"markup" or ["container_id", "path_to_menu_file"]
				});
			}
		}
		$('a[rel*=address:]').address();
		if ($('#ff_side_banner').is('*')) {
			sidebarAddition = $('#ff_Sidebar_Banner_Addition').html();
			$('#ff_side_banner').html( sidebarAddition );
		}
		(frankfeet.aBanners).sort(function() {return 0.5 - Math.random()});
		if ($('#banner_1').is('*')) {
			$('#banner_1').html( frankfeet.aBanners[0] );
		}
		if ($('#banner_2').is('*')) {
			$('#banner_2').html( frankfeet.aBanners[2] );
		}
		if ($('#banner_3').is('*')) {
			$('#banner_3').html( frankfeet.aBanners[3] );
		}
	},
	doInitMenus: function() {
		ddsmoothmenu.init({
			mainmenuid: "ff_mainmenu", //Menu DIV id
			orientation: 'v', //Horizontal or vertical menu: Set to "h" or "v"
			classname: 'ddsmoothmenu-v', //class added to menu's outer DIV
			customtheme: ["#993300", "#000000"],
			contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"]
		});
		ddsmoothmenu.init({
			mainmenuid: "ff_sidemenu", //Menu DIV id
			orientation: 'v', //Horizontal or vertical menu: Set to "h" or "v"
			classname: 'ddsmoothmenu-v', //class added to menu's outer DIV
			customtheme: ["#993300", "#000066"],
			contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"]
		});
	},
	doAjax: function( pFunction, aData ) {
		$.ajax({
			type: "GET",
			url: "/my_php/Frankfeet/ajax-galleries-data.php",
			cache: false,
			data: aData,
			datatype: 'json',
			success: pFunction,
			error: function() { alert("error"); }
		});
	},
	doAjaxStart: function( aSettings, pFunction ) {
		aSettings = $.extend( { collection: frankfeet.collection, gallerypos: frankfeet.gallery_pos, comment_id:comments.sId }, aSettings );
		frankfeet.doAjax( 
			function(data) {
				pFunction( JSON.parse(data) );
			},
			aSettings
		);
	},
	doInit: function() {
		frankfeet.hideDiv('#ff_content');
		frankfeet.showDiv('#ff_loading');
		frankfeet.doAjaxStart( {displaying: 'pictures'},
			function( data ) { 
				frankfeet.aPictures = data; 
				frankfeet.doAjaxStart( {displaying: 'gallery'},
				function( data ) {
					frankfeet.aGallery = data; 
					frankfeet.init = true;
					comments.sId = 'gallery_'+frankfeet.aGallery['gallery_id'];
					frankfeet.hideDiv('#ff_loading');
					frankfeet.showDiv('#ff_content');
					$('div.ff_title').html( frankfeet.getTitle() );
					$('div.ff_description').html( frankfeet.getDescription() );
					$('div.ff_quality').html( frankfeet.getQuality() );
					if ($('#ff_Sidebar_Header_Addition').is('*')) {
						sidebarAddition = $('#ff_Sidebar_Header_Addition').html();
						$('#ff_header_sidebar').append( sidebarAddition );
					}
					frankfeet.aBanners[0] = $('#ff_Banner1_Addition').html();
					frankfeet.aBanners[1] = $('#ff_Banner2_Addition').html();
					frankfeet.aBanners[2] = $('#ff_Banner3_Addition').html();
					frankfeet.onHash($.address.path());
					frankfeet.resizePage();
					frankfeet.doInitMenus();
				}
			)}
		);
	},
	doThis: function( todisplay ) { 
		if ( todisplay.search(/^picture_display_/) != -1 ) { 
			frankfeet.iScrollTop = $('#ff_content_container').scrollTop();
		} else { $('#ff_content_container').scrollTop( 0 ); }
		if (todisplay=='first_time') { frankfeet.doInit(); }
		else { frankfeet.display_Data( todisplay ); }
		if ( frankfeet.iScrollTop!=-1 && todisplay.search(/^picture_display_/) == -1 ) {
			$('#ff_content_container').scrollTop( frankfeet.iScrollTop );
			frankfeet.iScrollTop=-1;
		}
	},
	onHash: function( hash ) {
		if ( frankfeet.init ) {
			if (hash=='/') { frankfeet.doThis('first_page'); }
			else {
				frankfeet.doThis(hash.replace('/',''));
			}
		}
	},
	FILLER: null
}
$.address.change(function(event) {  
		// do something depending on the event.value property, e.g.  
		// $('#content').load(event.value + '.xml');
		thishash=event.value;
		frankfeet.onHash( thishash );
});

