/**
 * Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie (default: end of current session)
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 */
function setCookie(name, value, expires, path, domain, secure) {
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

/**
 * Deletes the specified cookie.
 *
 * name      name of the cookie
 * [path]    path of the cookie (must be same as path used to create cookie)
 * [domain]  domain of the cookie (must be same as domain used to create cookie)
 */
function deleteCookie(name, path, domain) {
    if (getCookie(name)) {
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}// tricos points Class
// (c) 2008 tricos media. All rights reserved.
// (p) Sascha Kimmel, tricos media.

// Built with prototype.js and script.aculo.us - what else? ;-)

var PointsClass = Class.create ({

	bubbleId:'tpBubble',
	imagePrefix:'/images/pointsbubble_',
	imageSuffix:'.png',
	div:null,
	img:null,
	width:0,
	height:0,
	isMSIE6:false,
	
	initialize:function(width, height)
	{
		this.isMSIE6 = (navigator.appVersion.indexOf("MSIE 6")>-1);
		this.width=width;
		this.height=height;
		this.div = new Element('div', { id:this.bubbleId, style:{ display:'none' } });
		$(document.body).appendChild(this.div);
		
		this.img = new Element('img');
		this.div.appendChild(this.img);
		
		// Preload images
		this.img.src=this.imagePrefix+5+this.imageSuffix;
		
		this.div.setStyle({
			display:'none',
			position:'absolute',
			left:'1px',
			top:'1px',
			width:width,
			height:height
		});
		
		if(this.isMSIE6) {
			this.div.setStyle({
				filter:"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+this.img.src+"', sizingMethod='scale')"
			});
		}
		
	},
	
	show:function(target, value)
	{
		// Retrieve current points value
		var points = parseInt($('tricosPointsValue').innerHTML);
		
		var imagePath = this.imagePrefix+value+this.imageSuffix;	
		
		if(this.isMSIE6) {
			this.div.setStyle({
				filter:"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+imagePath+"', sizingMethod='scale')"
			});
			this.img.src='/images/space.gif';
		} else {
			this.img.src=imagePath;
		}
	
		// What about waiting for it to load?
		
		// Get target info
		var targetDims    = Element.getDimensions($(target));
		var targetPos     = Element.cumulativeOffset($(target));
		var rightEdgeTop  = targetPos[1]+targetDims.height-2-this.height;
		var rightEdgeLeft = targetPos[0]+targetDims.width+4;

		// Position
		this.div.setStyle({ left:rightEdgeLeft+'px', top:rightEdgeTop+'px' });
		
		// Show
		new Effect.SlideDown(this.div);
		window.setTimeout(this.hide.bindAsEventListener(this), 2500);
		
		// Add points
		points += value;
		$('tricosPointsValue').update(points);
	},
	
	hide:function()
	{
		new Effect.SlideUp(this.div);
	}
	
});
// SilverModels Class
// (c) 2008 tricos media. All rights reserved.
// (p) Sascha Kimmel, tricos media.

// Built with prototype.js and script.aculo.us - what else? ;-)

var SilverModelsClass = Class.create ({
	
	infoDiv:null,
	blowupVisible:false,
	infoPop:null,
	
	initialize:function()
	{
		this.infoDiv = new Element('div', { id:'infoDiv' });
		$(document.body).appendChild(this.infoDiv);
		$('infoDiv').setStyle({
			display:'none',
			border:'1px solid #eee',
			backgroundColor:'white',
			padding:'5px',
			width:'400px',
			height:'300px',
			position:'absolute',
			left:'200px',
			top:'200px',
			zIndex:9000
		});
		
		// PANE
		var pane = new Element('div', { id:'pane' });
			$(document.body).appendChild(pane);
			pane.setStyle({
				display:'none',
				zIndex:8000,
				position:'absolute',
				backgroundColor:'#000',
				opacity:0.5
			});
			pane.observe('click', this.clearPane.bindAsEventListener(this));
			
		// Featurelist Homepage
		//alert($('hpTeaserList'));
		if($('hpTeaserList') != null) {
			var infoImages = $('hpTeaserList').select('img.info');
			if(infoImages.length > 0) {
				infoImages.each(function(i) {
					i.setStyle({ cursor:'pointer' });
					i.title='Klicken f�r Detail-Informationen';
					i.observe('mouseover', this.teaserListHover.bindAsEventListener(this));
					i.observe('mouseout', this.teaserListHoverOff.bindAsEventListener(this));
					i.observe('click', this.teaserListClick.bindAsEventListener(this));
				}.bind(this));
			}
		}


		// InfoPop
		var infoPop = $$('div.infopop');
		if (infoPop.length > 0) {
			var infoPop = infoPop[0];
			this.infoPop = infoPop;
			infoPop.down('a.btClose').observe('click', this.closeInfoPop.bindAsEventListener(this));
		}
		var infoPopOpeners = $$('a.infoPopLink');
		if (infoPopOpeners.length > 0) {
			infoPopOpeners.each(function(op) {
				op.observe('click', this.openInfoPop.bindAsEventListener(this));
			}.bind(this));
		}
	
        new Ajax.Request('/ajaxTrack.php', {
            parameters:
            {
                ref:document.referrer,
                page:location.href,
                awkey:this.getURLParam('gclid')
            }
        });
        
        Event.observe(window, 'unload', function() {
            new Ajax.Request('/ajaxTrack.php', {
                parameters:
                {
                    ref:document.referrer,
                    page:'__LEAVING_PAGE__',
                    awkey:this.getURLParam('gclid')
                }
            });
        }.bindAsEventListener(this));
		
//		if (smData.page	
	
		this.initModelList();
	},

	track:function(page, action, profile) {
		if (typeof page == 'undefined' || page == null) {
			page='';
		}
		if (typeof action == 'undefined' || action == null) {
			action='';
		}
		if (typeof profile == 'undefined' || profile == null) {
			profile = '';
		}
		new Ajax.Request('/s.php?r='+encodeURIComponent(document.referrer)+'&p='+page+'&a='+action+'&pr='+profile, { method:'get' });
	},

	closeInfoPop:function(e)
	{
		Event.stop(e);
		this.infoPop.hide();
		this.hidePane();
	},

	openInfoPop:function(e)
	{
		Event.stop(e);
		this.centerDivInDiv(this.infoPop, $('content'), 0, 0);
		var ofs = this.getVerticalScrollOffset()+50;
		this.infoPop.setStyle({ top:ofs+'px'  });
		this.showPane();
		this.infoPop.show();
		this.track();
	},


	showPane:function(callback)
	{
		var dims = $(document.body).getDimensions();
			
		if(navigator.appVersion.indexOf('MSIE') != -1) {
			var bodyDims = $(document.body).getDimensions();
			$('pane').setStyle({
				top:0,
				left:0,
				width:bodyDims.width,
				height:bodyDims.height
			});
		} else {
			Element.clonePosition($('pane'), $(document.body));
		}
		new Effect.Appear($('pane'), { to:0.5, duration:0.4, afterFinish:callback});
	},
	
	
	hidePane:function(callback)
	{
		new Effect.Fade($('pane'), { duration:0.4, afterFinish:callback });
	},
	
	
	clearPane:function(e)
	{
		if($('photoOverlay') == null) {
		if(e != null) Event.stop(e);
		new Effect.Fade(this.infoDiv);
		//if($('photoOverlay') != null) new Effect.Fade($('photoOverlay'));
		this.hidePane();
		}
	},
	
	getVerticalScrollOffset:function()
        {
                if (typeof window.pageYOffset == 'undefined') {
                        // IE
                        var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body;
                        var yOffset = iebody.scrollTop;
                } else {
                        // FF
                        var yOffset = window.pageYOffset; // + this.offsetTop;
                }
                return yOffset;
        },

	
	teaserListClick:function(e)
	{
		var img = Event.element(e);
		Event.stop(e);
		var feature='unknown';
		var cn=$w(img.className);
		cn.each(function(cl) {
			if(cl.match(/^nf_/)) {
				feature = cl.replace(/^nf_/, '');
			}
		});
		
		this.showPane(function() {
			this.showAjaxLoader();
			new Ajax.Request(
				'/ajax/feature.php',
				{
					method:'get',
					parameters:
					{
						w:feature
					},
					onSuccess:function(req)
					{
						this.hideAjaxLoader();
						$('infoDiv').update(req.responseText);
						this.centerDivInDiv($('infoDiv'), $('content'), 0, 0);
						new Effect.Appear($('infoDiv'));
					}.bind(this)
				}
			);
			
		}.bindAsEventListener(this));
		
	},
	
	
	
	teaserListHover:function(e)
	{
		var img = Event.element(e);
		img.src='/images/info_hover.gif';
	},
	
	teaserListHoverOff:function(e)
	{
		var img = Event.element(e);
		img.src='/images/info.gif';
	},
	
	showAjaxLoader:function(yOffset)
	{
		if (yOffset == null) yOffset = 0;
//		yOffset+=this.getVerticalScrollOffset();
		if($('ajaxLoader') == null) {
			var loader = new Element('div', { id:'ajaxLoader' });
			$(document.body).appendChild(loader);
			loader.setStyle({
				display:'none',
				width:'32px',
				height:'32px',
				border:'1px dotted black',
				position:'absolute',
				padding:'20px',
				backgroundColor:'white',
				zIndex:8500
			});
			var img = new Element('img', { src:'/images/ajax-loader-pane.gif'});
			loader.appendChild(img);
		}
		this.centerDivInDiv($('ajaxLoader'), $('content'), 0, 0);
		if (yOffset > 0) {
			$('ajaxLoader').setStyle({ top: yOffset+'px' });
		}
//		alert(this.getVerticalScrollOffset());
		$('ajaxLoader').show();
	},
	
	hideAjaxLoader:function()
	{
		$('ajaxLoader').hide();
	},
	
	centerDivInDiv:function(divToCenter, divToCenterIn, xOffset, yOffset) {
		var fullDIVSize=document.viewport.getDimensions();
		var fullDivWidth=fullDIVSize.width;
		var fullDivHeight=fullDIVSize.height;
		var divToCenterSize=divToCenter.getDimensions();
		var divToCenterWidth=divToCenterSize.width;
		var divToCenterHeight=divToCenterSize.height;
		var divOffsetX=Math.round((fullDivWidth-divToCenterWidth)/2);
		var divOffsetY=Math.round((fullDivHeight-divToCenterHeight)/2);
		$(divToCenter).setStyle({
			left:(divOffsetX+xOffset)+'px',
			top:(divOffsetY+yOffset)+'px'
		});
	},
	
	// For the models list
	initModelList:function()
	{
		var modelList = $$('div.profilePreview');
		if(modelList.length > 0) {
			modelList.each(function(m) {
				$(m).observe('mouseover', function(e) {
					var el=Event.element(e);
					var elm = $(el).up('div.profilePreview');
					if(elm != null) {
						$(elm).setStyle({ backgroundColor:'#eeeeee', border:'1px solid #a0397e' });
					}
				});
	
				$(m).observe('mouseout', function(e) {
                        var el=Event.element(e);
                        var elm = $(el).up('div.profilePreview');
                        if(elm != null) {
                                $(elm).setStyle({ backgroundColor:'#ffffff', border:'1px solid #eeeeee' });
                        }
                });
	
			});
		}
	},



	// SLightly modified for non-sedcard usage from sedcard.class.js
	blowupPhoto:function(img)
	{
//		var img = $('mainPhotoID');
		this.showPane();
		this.showAjaxLoader();
		
		if($('tempImage') == null) {
			var tempImg = new Element('img', { id:'tempImage' });
			$(document.body).appendChild(tempImg);
		}
		
		if($('photoOverlay') == null) {
			var overlay = new Element('div', { id:'photoOverlay' });
			$(document.body).appendChild(overlay);
			overlay.setStyle({
				display:'none',
				position:'absolute',
				top:0,
				left:0,
				padding:'2px',
				backgroundColor:'white',
				cursor:'pointer'
			});
			
			$('photoOverlay').observe('contextmenu', function(e) {
				Event.stop(e);
			});
			
			$('photoOverlay').observe('click', function(e) {		
				if (Event.element(e).tagName.toLowerCase() != 'a') {
					Event.stop(e);
				}
				new Effect.Fade($('photoOverlay'));
				silvermodels.hidePane();
				this.blowupVisible=false;
				$('photoOverlay').remove();
				//$('tempImage').remove();
			}.bindAsEventListener(this));
		}
		
		$('tempImage').galleryimg='no';
		$('tempImage').setStyle({position:'absolute', display:'block', top:0, left:'-2000px'});
		$('tempImage').hide();
		
		// Read image path
		var newSrc = img.src.match(/\/photos\/([0-9]+)\/([0-9]+)_thumb\.jpg$/);
		var id1 = newSrc[1];
		var id2 = newSrc[2];
		newSrc  = '/photos/'+id1+'/'+id2+'_member.jpg';
		//console.log(newSrc);
		
		$('tempImage').observe('load', function(e) {
			//console.log('LOADED!');
			//console.log(this.blowupVisible);
			if(this.blowupVisible == false) {
				var imgDims = $('tempImage').getDimensions();
				var imgW = imgDims.width;
				var imgH = imgDims.height;
				$('photoOverlay').appendChild($('tempImage'));
				$('tempImage').setStyle({
					marginTop:'5px',
					marginLeft:'5px'
				});
				
				// Add title
				if($('photoDescription') == null) {
					var photoDesc = new Element('div', { id:'photoDescription' });
					$('photoOverlay').appendChild(photoDesc);
					photoDesc.setStyle({
						backgroundColor:'#fff',
						padding:'5px',
						color:'#666666',
						marginTop:(imgH)+'px',
						overflow:'hidden'
					});
				}
				
				$('photoDescription').update('<strong><a href="/sedcard.'+img.title+'.html">Zur Sedcard von '+img.title+'</a>');
				
				$('photoOverlay').setStyle({
					width:(imgW+5)+'px',
					height:(imgH+40)+'px',
					zIndex:22222
				});
				$('tempImage').setStyle({ top:0, left:0 });
				$('tempImage').show();
				this.centerDivInDiv($('photoOverlay'), null, 0, 0);
				this.hideAjaxLoader();
				new Effect.Appear($('photoOverlay'));
				this.blowupVisible=true;
				location.href='#';
			}
		}.bindAsEventListener(this));
		
		if(this.blowupVisible == false) {
			// Force loading
			$('tempImage').src=newSrc;
		}
		
		/*
		$('tempImage').remove();
		*/
	},
    
    getURLParam:function(strParamName){
        var strReturn = "";
        var strHref = window.location.href;
        if ( strHref.indexOf("?") > -1 ){
            var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
            var aQueryString = strQueryString.split("&");
            for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
                if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
                    var aParam = aQueryString[iParam].split("=");
                    strReturn = aParam[1];
                    break;
                }
            }
        }
        return strReturn;
    }

	
});
// SilverModels Class
// (c) 2008 tricos media. All rights reserved.
// (p) Sascha Kimmel, tricos media.

// Built with prototype.js and script.aculo.us - what else? ;-)

var SedcardClass = Class.create ({

	model:null,
	profileId:null,
	ratingValues:[],
	resetTimer:null,
	loggedin:0,
	rated:0,
	ratingCount:0,
	pointsObj:null,
	blowupVisible:false,
	isMSIE6:false,

	commentValue:'',
	
	initialize:function(model, profileId, rated, loggedin)
	{
		this.isMSIE6 = (navigator.appVersion.indexOf("MSIE 6")>-1);
		this.model = model;
		this.profileId = profileId;
		this.rated = rated;
		this.loggedin = loggedin;

		// Button
                if ($('topBtLink') != null) {
                        $('topBtLink').observe('click', function(e) {
                                Event.stop(e);
                                $('topBtInfo').show();
                                $('topBtLink').hide();
                        });
                }

		
		$('ratingBoxTD').appendChild($('ajaxindicator'));
		$('ajaxindicator').show();
		$('ratingBox').show();
		
		// Create 3D effect, required reflection.js
		/*
		var ref3D = new Reflect3D($$('div.3dimagereflect')[0]);
		ref3D.init();
		*/
		
		// Create points object
		this.pointsObj = new PointsClass(118, 77);
		
		var photos = $$('img.modelphoto');
		if(photos.length > 0) {
			photos.each(function(photo) {
				photo.setStyle({cursor:'pointer'});
				photo.up('a').observe('click', this.blowupPhoto.bindAsEventListener(this));
/*
				photo.observe('click', function(e) {
					img=Event.element(e);	
	
					var mainPhoto = $('mainPhotoID');
					mainPhoto.setStyle({ display:'block' });
					mainPhoto.width=img.getAttribute('smw');
					mainPhoto.height=img.getAttribute('smh');
		
					if(document.all) {
						mainPhoto.style.filter="blendTrans(duration=1)";
						mainPhoto.filters.blendTrans(duration=1).Apply();
						mainPhoto.filters.blendTrans.Play();
					} else {
						mainPhoto.hide();
					}	
					mainPhoto.src='http://'+location.hostname+'/photos/'+img.getAttribute('smpid')+'/'+img.getAttribute('smhid')+'_resized.jpg';
					if(!document.all) {
						new Effect.Appear(mainPhoto);
					}
					
			        currentPhoto='/photos/'+img.getAttribute('smpid')+'/'+img.getAttribute('smhid')+'_member.jpg';
			        currentPhotoW=img.getAttribute('smmw');
			        currentPhotoH=img.getAttribute('smmh');
					$('mainPhotoID').title = img.getAttribute('title').escapeHTML();
					$('mainphotoDiv').setStyle({ paddingLeft:(Math.round((423-$('mainPhotoID').getWidth()-35)/2))+'px' });
					Event.stop(e);
				});
				*/

			}.bind(this));
		}
		
		// Add event listener for blow-up photos
		if($('mainPhotoID') != null) {
			$('mainPhotoID').observe('click', this.blowupPhoto.bindAsEventListener(this));
			$('mainPhotoID').setStyle({ cursor:'pointer' });
			
/*
			// Show to the user
			var blowUpImg = new Element('img', { id:'blowUpMarker', src:'/images/blowup.png' });
			$('mainPhotoID').setStyle({ border:'3px solid white', cursor:'pointer' });
			$('mainphotoDiv').appendChild(blowUpImg);
			$('mainphotoDiv').setStyle({ paddingLeft:(Math.round((423-$('mainPhotoID').getWidth()-35)/2))+'px' });
			//$('mainphotoDiv').setStyle({ width:'423px', overflow:'hidden' });
			blowUpImg.setStyle({ cursor:'pointer', float:'left' });
//			$('mainPhotoID').setStyle({ float:'left' });
			blowUpImg.observe('click', this.blowupPhoto.bindAsEventListener(this));

*/
			/*
			$('blowUpMarker').setStyle({
				filter:"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+'/images/blowup.png'+"', sizingMethod='scale')"
			});
			*/
		}
		
	   this.loadRatingBox();
	},

  loadRatingBox:function()
  {
    	// Load rating stuff
		var aj = new Ajax.Request (
			"/ajax/getRatingBox.php", 
			{
				method: 'get',
				parameters: 'model='+encodeURIComponent(this.model)+'&id='+this.profileId,
				onComplete: function (req) {
					if (req.responseText.match(/Error/)) {
						
					} else {
					 var alreadyThere = false;
					 if ($('rating') == null) {
						  var ratingDiv = new Element('div', { id: 'rating' });
						  $('ratingBoxTD').appendChild(ratingDiv);
						} else {
						  alreadyThere = true;
              var ratingDiv = $('ratingDiv');
            }
						// console.log(req.responseText);
						$('ajaxindicator').hide();
						ratingDiv.update(req.responseText);
						
						var ratingStatus=$('ratingTitle').getAttribute('rtStatus');
						if(ratingStatus=='notrated') {
							var images = $$('#starlist img');
							this.ratingValues = [];
							if(images.length > 0) {
								images.each(function(img) {
									if(img.src.match(/star.gif/)) {
										this.ratingValues.push(0);
									} else {
										this.ratingValues.push(1);
									}
									if(this.rated == 0) {
										$(img).setStyle({ cursor:'pointer'});
										$(img).observe('mouseover', this.starHoverOn.bindAsEventListener(this));
										$(img).observe('mouseout', this.starHoverOff.bindAsEventListener(this));
										$(img).observe('click', this.saveRating.bindAsEventListener(this));
									}
								}.bind(this));
							}

						}
						if($('ratingCount') != null) {
							this.ratingCount = parseInt($('ratingCount').innerHTML);
						}


						// Comment editor?
            if ($('commentLink') != null) {
              // User is logged in and has not yet added a textual comment and is shown the "enter a comment" box
              $('commentLink').observe('click', this.commentShowEditor.bindAsEventListener(this));

          		if ($("commentSaveLink") != null) {
          			$("commentSaveLink").observe('click', this.commentSave.bindAsEventListener(this));
          		}
		
		          if ($("commentSaveCancelLink") != null) {
                $("commentSaveCancelLink").observe('click', this.commentSaveCancel.bindAsEventListener(this));
                }
                
              if ($("commentEditLink") != null) {
                $("commentEditLink").observe('click', this.commentShowEditor.bindAsEventListener(this));
              }
              
              if ($("commentDeleteLink") != null) {
                $("commentDeleteLink").observe('click', this.commentDelete.bindAsEventListener(this));
              }
            }

						$('ratingBox').show();
					}
				}.bind(this)
			}
		);	
  },

	commentShowEditor:function(e)
  {
    Event.stop(e);
	//	$('commentInfo').hide();
		new Effect.SlideUp($('commentInfo'), {
			afterFinish:function(){
				new Effect.SlideDown($('commentEditor'), {
					afterFinish:function() {
						$("commentEditorForm").down('textarea').focus();
					}
				});
			}
		});
  },

  commentDelete:function(e)
  {
    Event.stop(e);
    var aj = new Ajax.Request (
      "/ajax/deleteRatingComment.php",
      {
        parameters: {
					model:this.model,
					id:this.profileId
				},
        onComplete: function (req) {
           $('commentText').update('');
           $('commentEditorForm').down('textarea').setValue('');
           $('commentNotRated').show();
           $('commentAlreadyRated').hide();
        /*
					this.commentValue = val;
					new Effect.SlideUp($('commentEditor'), {
        			afterFinish:function(){
        			console.log(1);
                      new Effect.SlideDown($('commentInfo'));
                      console.log(2);
                      $('commentText').update(val);
                      console.log(3);
                      $('commentNotRated').hide();
                      console.log(4);
                      $('commentAlreadyRated').show();
                      console.log(5);
        			}
			    });
        */
        }.bind(this)
      });
  },

	commentSave:function(e)
	{
		Event.stop(e);
		var val = $("commentEditorForm").down('textarea').getValue();
		var aj = new Ajax.Request (
      "/ajax/saveRatingComment.php",
      {
        parameters: {
					model:this.model,
					id:this.profileId,
					comment:val
				},
        onComplete: function (req, json) {
        var jsonObj = req.responseText.toJSON();
        console.log(jsonObj);
					this.commentValue = val;
					new Effect.SlideUp($('commentEditor'), {
        			afterFinish:function(){
                      new Effect.SlideDown($('commentInfo'));
                      $('commentText').update(req.responseText);
                      $('commentNotRated').hide();
                      $('commentAlreadyRated').show();
        			}
			    });

        }.bind(this)
      });
	},

	commentSaveCancel:function(e)
	{
		Event.stop(e);
		$("commentEditorForm").down('textarea').value = '';
		new Effect.SlideUp($('commentEditor'), {
			afterFinish:function(){
				new Effect.SlideDown($('commentInfo'));
			}
		});

	},


	getVerticalScrollOffset:function()
	{
		if (typeof window.pageYOffset == 'undefined') {
			// IE
			var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body;
			var yOffset = iebody.scrollTop; 
		} else {
			// FF
			var yOffset = window.pageYOffset; // + this.offsetTop;
		}
		return yOffset;
	},
	
	
	blowupPhoto:function(e)
	{
		var img = $('mainPhotoID');
		var eventEl = Event.element(e);
		img = eventEl;
		Event.stop(e);

		var yPos = this.getVerticalScrollOffset() + 50;

		silvermodels.showPane();
		silvermodels.showAjaxLoader(yPos);
		
		if($('tempImage') == null) {
			var tempImg = new Element('img', { id:'tempImage' });
			$(document.body).appendChild(tempImg);
		}
		
		if($('photoOverlay') == null) {
			var overlay = new Element('div', { id:'photoOverlay' });
			$(document.body).appendChild(overlay);
			overlay.setStyle({
				display:'none',
				position:'absolute',
				top:0,
				left:0,
				padding:'2px',
				'backgroundColor':'white',
				cursor:'pointer'
			});
			
			$('photoOverlay').observe('contextmenu', function(e) {
				Event.stop(e);
			});
			
			$('photoOverlay').observe('click', function(e) {	
				var elu = Event.element(e);
				if (typeof elu.id != 'undefined' && elu.id == 'photoPermaLink') {
				} else {
					Event.stop(e);
					new Effect.Fade($('photoOverlay'));
					silvermodels.hidePane();
					this.blowupVisible=false;
					$('photoOverlay').remove();
					//$('tempImage').remove();
				}
			}.bindAsEventListener(this));
		}
		
		$('tempImage').galleryimg='no';
		var yPos = this.getVerticalScrollOffset() + 50;
		$('tempImage').setStyle({position:'absolute', display:'block', top:0, left:'-2000px'});
		$('tempImage').hide();
		
		// Read image path
		var newSrc = img.src.match(/\/photos\/([0-9]+)\/([0-9]+)_(resized|thumb)\.jpg$/);
		var id1 = newSrc[1];
		var id2 = newSrc[2];
		newSrc  = '/photos/'+id1+'/'+id2+'_member.jpg';
		//console.log(newSrc);
		
		$('tempImage').observe('load', function(e) {
			//console.log('LOADED!');
			//console.log(this.blowupVisible);
			if(this.blowupVisible == false) {
				var imgDims = $('tempImage').getDimensions();
				var imgW = imgDims.width;
				var imgH = imgDims.height;
				$('photoOverlay').appendChild($('tempImage'));
				$('tempImage').setStyle({
					marginTop:'5px',
					marginLeft:'5px'
				});
				
				// Add title
				if($('photoDescription') == null) {
					var photoDesc = new Element('div', { id:'photoDescription' });
					$('photoOverlay').appendChild(photoDesc);
					photoDesc.setStyle({
						backgroundColor:'#fff',
						padding:'5px',
						color:'#666666',
						marginTop:(imgH)+'px',
						overflow:'hidden'
					});
				}

				var ttl = $('mainPhotoID').title;
                                var permalink = '';
				var imgSrc = $('tempImage').src;
				var u = imgSrc.match(/\/photos\/([0-9]+)\/([0-9]+)/);
				if (u != null) {
					permalink = '<a id="photoPermaLink" href="http://www.silvermodels.de/photos/'+u[1]+'/'+u[2]+'_member.jpg" target="_blank">Permalink</a>';
				}
                                if (ttl.length > 0) {
                                        $('photoDescription').update('<strong>Beschreibung</strong><br />"'+$('mainPhotoID').title+'"<br />'+permalink);
                                } else {
                                        $('photoDescription').update('<strong>Beschreibung</strong><br />- keine angegeben -<br />'+permalink);
                                }


				
//				$('photoDescription').update('<strong>Beschreibung</strong><br />'+$('mainPhotoID').title);
				
				$('photoOverlay').setStyle({
					width:(imgW+5)+'px',
					height:(imgH+40+25)+'px',
					zIndex:22222
				});
				$('tempImage').setStyle({ top:0, left:0 });
				$('tempImage').show();
				silvermodels.centerDivInDiv($('photoOverlay'), null, 0, 0);

				var newYPos = yPos+'px';
				$('photoOverlay').setStyle({ top: newYPos });
				silvermodels.hideAjaxLoader();
				new Effect.Appear($('photoOverlay'));
				this.blowupVisible=true;
			}
		}.bindAsEventListener(this));
		
		if(this.blowupVisible == false) {
			// Force loading
			$('tempImage').src=newSrc;
		}
		
		/*
		$('tempImage').remove();
		*/
	},
	
	freeze:function()
	{
		for(i=1; i<=5; i++) {
			var img = $('star'+i);
			$(img).stopObserving('mouseover', this.starHoverOn.bindAsEventListener(this));
			$(img).stopObserving('mouseout', this.starHoverOff.bindAsEventListener(this));
			$(img).stopObserving('click', this.saveRating.bindAsEventListener(this));
			$(img).setStyle({ cursor:'default' });
		}
	},
	
	
	starHoverOn:function(e) 
	{
		if(this.resetTimer != null) {
			window.clearTimeout(this.resetTimer);
		}
		if(this.rated == 1) return;
		
		for(i=1; i<=5; i++) {
			$('star'+i).src = '/images/star.gif';
		}
		var img = Event.element(e);
		var imgId = img.id.replace(/star/, '', img.id);
		for(i=1; i<=imgId; i++) {
			$('star'+i).src = '/images/star1.gif';
		}
	},
	
	starHoverOff:function(e) 
	{
		if(this.rated == 1) return;
		var img = Event.element(e);
		var imgId = img.id.replace(/star/, '', img.id);
		for(i=imgId; i>0; i--) {
			$('star'+i).src = '/images/star.gif';
		}
		this.resetTimer = window.setTimeout(this.resetRating.bindAsEventListener(this), 1000);
	},
	
	saveRating:function(e)
	{
		Event.stop(e);
		if(this.rated) return false;
		
		var img = Event.element(e);
		var ratingValue = img.id.replace(/star/, '', img.id);
		
		this.freeze();
		this.rated=1;
		this.ratingCount++;
		var aj = new Ajax.Request (
			"/ajax/saveRating.php", 
			{
				method: 'get',
				parameters: 'model='+encodeURIComponent(this.model)+'&id='+this.profileId+'&rating='+ratingValue,
				onComplete: function (req) {
					// console.log('SUCCESS!');
					$('ratingTitle').setStyle({ color:'#c40000'});
					$('ratingTitle').update('Vielen Dank!');
					if($('ratingCount') != null) $('ratingCount').update(this.ratingCount);
					this.pointsObj.show($('starlist'), 5);
				}.bind(this)
			}
		);
						
	},
	
	resetRating:function()
	{
		if(this.ratingValues.length > 0) {
			for(i=1; i<6; i++) {
				if(this.ratingValues[i-1] == 0) {
					$('star'+i).src='/images/star.gif';
				} else {
					$('star'+i).src='/images/star1.gif';
				}
			}
		}
	}
	
});
// silvermodels V1.0 JavaScript SourceCode
// (c) 2006 by tricos media. All rights reserved.
// [TCB] 04.02.2006 17:42:58

var mainProjectDomain="www.silvermodels.de";

function doPopup(url, width, height)
{
	tspopmywin=window.open(url, 'tsPopup', 'width='+width+',height='+height+',directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=no');
	tspopmywin.focus();
}

function swapImage(img, src)
{
	document.images[img].src="images/"+src;
}


function setSelRange(inputEl, selStart, selEnd) { 
 if (inputEl.setSelectionRange) { 
  inputEl.focus(); 
  inputEl.setSelectionRange(selStart, selEnd); 
 } else if (inputEl.createTextRange) { 
  var range = inputEl.createTextRange(); 
  range.collapse(true); 
  range.moveEnd('character', selEnd); 
  range.moveStart('character', selStart); 
  range.select(); 
 } 
}



function askUser(question, actionURL)
{
	if(window.confirm(question)) {
		top.location.href=actionURL;
		return true;
	}
}

var silvermodels;
Event.observe(window, 'load', function() {
	silvermodels = new SilverModelsClass();
});
