/*
	date: 2007-03-25
	version: 0.0.4
*/
document.domain = "clubzone.es";

function popUp(u,n,w,h,e){
	var s = "width=" + w + ",height=" + h;
	s += ",left=" + (screen.width-w)/2 + ",top=" + parseInt((screen.height-h)/3);
	if(e) { s += "," + e; }
	pw = window.open(u,n,s);
	pw.focus();
}

function textCounter(ele, maxlimit)
{
	if (ele.value.length > maxlimit) {
		ele.value = ele.value.substring(0, maxlimit);
	}
}




function setScrollToTop() { 
    window.scrollTo(0, 0); 
}


var frameService = {
    loaded: function(obj)
    {
        this.obj = obj;
        this.doc = obj.contentDocument || obj.contentWindow.document || obj.document || false;
        if (this.doc)
        {
            this.height(this.obj, this.doc);
            setTimeout("frameService.height()", 1); // Safari delay fix
            if (DetectFlashVer(8, 0, 0)) this.headlines(this.doc);

            setTimeout('setScrollToTop()', 30);
        }
    },
    popup: function()
    {
        if (DetectFlashVer(8, 0, 0)) frameService.headlines(document);
    },
    stateChange: function()
    {
    },
    height: function()
    {
        var divs = this.doc.getElementsByTagName("div");
        if (divs.length > 0)
        {
            this.obj.style.height = divs[0].offsetHeight + "px";
        }
    },
    headlines: function(doc)
    {
        var h4 = doc.getElementsByTagName("h4");
        for (var i = 0; i < h4.length; i++)
        {
            if (h4[i].className == 'headline')
            {
                if (h4[i].firstChild.type != '')
                {
                    var text = h4[i].firstChild.nodeValue.toUpperCase();
                    var href = h4[i].name;
                    if (href == 'undefined')
                        h4[i].innerHTML = this.getFlashString(text);
                    else
                        h4[i].innerHTML = this.getFlashString(text, href);
                    h4[i].firstChild.style.marginLeft = "-2px";
                }
            }
        }
    },
    getFlashString: function(text, href, id)
    {
        top.returnFlashString = true;
        if (href != null)
        {
            var string = AC_FL_RunContent(
			'codebase', 'http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab',
			'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
			'quality', 'high',
			'play', 'true',
			'loop', 'false',
			'scale', 'noScale',
			'menu', 'false',
			'devicefont', 'false',
			'wmode', 'transparent',
			'allowScriptAccess', 'sameDomain',
			'width', '220',
			'height', '20',
			'movie', '/swf/headline',
			'id', 'id',
			'FlashVars', ('href=/' + href + '&txt=' + text)
		);
        }
        else
        {
            var string = AC_FL_RunContent(
			'codebase', 'http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab',
			'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
			'quality', 'high',
			'play', 'true',
			'loop', 'false',
			'scale', 'noScale',
			'menu', 'false',
			'devicefont', 'false',
			'wmode', 'transparent',
			'allowScriptAccess', 'sameDomain',
			'width', '220',
			'height', '20',
			'movie', '/swf/headline',
			'id', 'id',
			'FlashVars', ('txt=' + text)
		);
        }
        return string;
    }
}

var checkbox = {
	change: function(state){
		var inputs = document.getElementsByTagName('input');
		for (var i=0; i<inputs.length; i++) {
			if (inputs[i].type=='checkbox') inputs[i].checked = state;
		}
	},
	submit: function(url){
		var collection = [];
		var inputs = document.getElementsByTagName('input');
		for (var i=0; i<inputs.length; i++) {
			if (inputs[i].type=='checkbox' && inputs[i].checked==true) collection.push(inputs[i].id)
		}
		if (collection.length>0) location.href = url+collection;
	}
}

var gallery = {
	init: function(path, startIndex, textEditID, currentPictureID, starIds, currentPhotoButtonID, previousPageUrl, nextPageUrl ){
		this.path = path;
		this.starIds = starIds;
		this.currentPhoto = document.getElementById('currentPhoto');
		this.currentPhotoButton = document.getElementById(currentPhotoButtonID)||false;
		this.currentPicture = document.getElementById(currentPictureID);
		this.photoNames = document.getElementById('photoNames')||false;
		this.currentText = document.getElementById('currentText')||false;
		this.currentTextEdit = document.getElementById(textEditID) || false;
		this.smallPhotos = document.getElementById('smallPhotos') || false;
		this.profileName = document.getElementById('profileName') || false;
		this.previousPageUrl = null;
		this.nextPageUrl = null;

        if( previousPageUrl )
        {
            this.createNavigator( this.smallPhotos, '/img/btn/filmstrip_prev.jpg', '', previousPageUrl );
            this.previousPageUrl = previousPageUrl;
        }
        
		this.index = {};
		for (var i=0; i<photoAlbum.length; i++) {
			this.createPhoto(this.smallPhotos, photoAlbum[i].smallThumbnailUrl, false, true, "", "", photoAlbum[i].id, photoAlbum[i].isRated, photoAlbum[i].rating)
			this.index[photoAlbum[i].id] = { ref: i, src: photoAlbum[i].largeImageUrl, isRated: photoAlbum[i].isRated, rating: photoAlbum[i].rating};
		}
		
        if( nextPageUrl )
        {
            this.createNavigator( this.smallPhotos, '/img/btn/filmstrip_next.jpg', '', nextPageUrl );
            this.nextPageUrl = nextPageUrl;
        }

		//this.createPhoto(this.currentPhoto, photoAlbum[startIndex].largeImageUrl, photoAlbum[startIndex].pictureText, false, this.photoNames, photoAlbum[startIndex].names, photoAlbum[startIndex].id, photoAlbum[startIndex].isRated, photoAlbum[startIndex].rating);
		this.current = startIndex;
        this.changePhoto();
		if (this.currentTextEdit) this.currentTextEdit.focus();
	},
	createNavigator: function(target, src, text, url)
	{
	    var img = document.createElement( 'img' );
	    img.src = src;
	    img.onclick = new Function( "location.href = '" + url + "';" );
	    if( text ) img.alt = text;
	    if( target ) target.appendChild( img );
	},
	createPhoto: function(target, src, text, view, nameTarget, nameList, imageId, isRated, rating){
		var img = document.createElement('img');
		img.src = this.path + src;
		img.id = imageId;		
		if (view) img.onclick = new Function("gallery.thisPhoto(this)");
		if (target) target.appendChild(img);

		if (text) { 
			if (this.currentText) this.currentText.replaceChild(document.createTextNode(text), this.currentText.firstChild);
			if (this.currentTextEdit) this.currentTextEdit.value = text;
		}
		if (this.photoNames && nameList && nameList.length>0){
			for (var i=0; i<nameList.length;  i++) {
				var name = document.createElement('div');
				name.style.left = nameList[i][1] + "px"
				var link = document.createElement('a');
				link.href = nameList[i][2]
				link.appendChild(document.createTextNode(nameList[i][0]))
				name.appendChild(link)		
				nameTarget.appendChild(name);
			}
		}
	},
	nextPhoto: function()
	{
	    if( this.current == photoAlbum.length - 1 )
	    {
	        if( this.nextPageUrl != null )
	        {
	            location.href = this.nextPageUrl;
	        }
	    }
	    else
	    {
	        this.current++;
	        this.changePhoto();
	    }
	},
	nextPhotoWithAlertAtEnd: function(txt){
		this.current = (this.current == photoAlbum.length-1) ? 0 : this.current+1;
		this.changePhoto();
		if (this.current == photoAlbum.length-1) {
		    alert(txt);
		}
	},
	prevPhoto: function()
	{
	    if( this.current == 0 )
	    {
	        if( this.previousPageUrl != null )
	        {
	            location.href = this.previousPageUrl;
	        }
	    }
	    else
	    {
	        this.current--;
	        this.changePhoto();
	    }
	},
	thisPhoto: function(obj){
		this.current = this.index[obj.id].ref;
		this.changePhoto();
	},
	initPhoto: function(image){
	},
	switchIdentifyOnPicture: function(turnOn){
		if (turnOn){
			if (this.currentPhoto) this.currentPhoto.style.display = 'none';
			if (this.currentPhotoButton){
				this.currentPhotoButton.style.background = this.currentPhoto.style.background; 
				this.currentPhotoButton.style.display = 'block';
			}
		}
		else{
			if (this.currentPhotoButton) this.currentPhotoButton.style.display = 'none';
			if (this.currentPhoto) this.currentPhoto.style.display = 'block';
		}
	},
		switchPicture: function(){
	    this.currentPhoto.style.display = 'none';
	    this.currentPhotoButton.style.display = "block";
	    this.currentPhotoButton.style.background = 'url(\'' + this.path + photoAlbum[this.current].largeImageUrl + '\') no-repeat center center';
	},
	getPhoto: function(){
	    return this.path + photoAlbum[this.current].largeImageUrl;
	},
	changePhoto: function(src, text){
		if (photoAlbum.length == 0){
			return;
		}
		this.switchIdentifyOnPicture(false);
		this.currentPicture.value = photoAlbum[this.current].id;

        var oldPhotoStyle = this.currentPhoto.style.background;
        var newPhotoStyle = 'url(\'' + this.path + photoAlbum[this.current].largeImageUrl + '\') no-repeat center center';
		this.currentPhoto.style.background = newPhotoStyle;
		
        if (this.profileName) this.profileName.innerHTML = photoAlbum[this.current].profileName;
		if (this.currentText) this.currentText.replaceChild(document.createTextNode(photoAlbum[this.current].pictureText), this.currentText.firstChild);
		if (this.currentTextEdit) this.currentTextEdit.value = photoAlbum[this.current].pictureText;

        // Show rating buttons on the left
		var sendPictureToRatingDiv = document.getElementById('SendPictureToRating') || false;
		var ratingDiv = document.getElementById('PictureRating') || false;
		if (sendPictureToRatingDiv && ratingDiv){
		    if (photoAlbum[this.current].isRated == 1){
		        sendPictureToRatingDiv.style.display = "none";
		        ratingDiv.style.display = "none";
		        ratingDiv.firstChild.innerHTML = photoAlbum[this.current].rating;
		    }
		    else{
		        sendPictureToRatingDiv.style.display = "block";
		        ratingDiv.style.display = "none";
		    }
		}
		
		// toggle visibility for the previous button
		var button;
		button = document.getElementById( 'galleryPrevButton' );
		if( button )
		{
		    if( this.current == 0 && this.previousPageUrl == null ) button.style.display = 'none';
		    else button.style.display = 'block';
		}
		// toggle visibility for the next button
		button = document.getElementById( 'galleryNextButton' );
		if( button )
		{
		    if( this.current == photoAlbum.length - 1 && this.nextPageUrl == null ) button.style.display = 'none';
		    else button.style.display = 'block';
		}
		
		if( oldPhotoStyle.length > 0 && oldPhotoStyle != newPhotoStyle )
		{
		    if( HideClickYourself ) HideClickYourself();
		    if( HideMessageBox ) HideMessageBox();
		}


        // Show rating for previous picture in rating view - has been changed as it's no longer the previous picture that is shown
/*        
        var prevPictureSmallThumbnail = document.getElementById('prevPictureSmallThumbnail') || false;
        var prevPictureRating = document.getElementById('prevPictureRating') || false;
        var prevPictureNumberOfRatings = document.getElementById('prevPictureNumberOfRatings') || false;
        var prevIndex = (this.current == 0) ? photoAlbum.length-1 : this.current-1;
        if (prevPictureSmallThumbnail){
		    var img = document.createElement('img');
		    img.src = this.path + photoAlbum[prevIndex].smallThumbnailUrl;
		    prevPictureSmallThumbnail.replaceChild(img, prevPictureSmallThumbnail.firstChild);
        }
        if (prevPictureRating){
            prevPictureRating.firstChild.innerHTML = photoAlbum[prevIndex].rating;
        }
        if (prevPictureNumberOfRatings){
            prevPictureNumberOfRatings.firstChild.innerHTML = photoAlbum[prevIndex].numberOfRatings;
        }
*/        

        // Show rating stars
        if (this.starIds != null){
			for (var i = 0; i < this.starIds.length;  i++) {
				var star = document.getElementById(this.starIds[i]) || false;
				if (star){
					if (i + 1 <= photoAlbum[this.current].yourRating)
						star.className = 'ratingStarHot';
					else
						star.className = 'ratingStarNot';
				
				}
			}
	    }
		
		
		// Top rated pictures have some special fields
		var profileIconsElement = document.getElementById('profileIcons') || false;
		if (profileIconsElement){
			profileIconsElement.innerHTML = photoAlbum[this.current].profileIcons;

			var profileNameElement = document.getElementById('profileName') || false;
			if (profileNameElement){
				profileNameElement.innerHTML = photoAlbum[this.current].profileName;
				profileNameElement.href = photoAlbum[this.current].profileUrl
			}
			

			var ratingElement = document.getElementById('PictureRating2') || false;
			if (ratingElement) ratingElement.firstChild.innerHTML = photoAlbum[this.current].rating;
		}
		var rankElement = document.getElementById('ranking') || false;
		if (rankElement){
			rankElement.innerHTML = photoAlbum[this.current].rank;
		}


        // Show names on photo
		if (this.photoNames){
			for (var i=this.photoNames.childNodes.length; i>0; i--){
				this.photoNames.removeChild(this.photoNames.childNodes[i-1])
			}
		    var nameList = photoAlbum[this.current].names;
			var identifyOnPictureElement = document.getElementById('identifyOnPicture') || false;
			var removeMeFromPictureElement = document.getElementById('removeMeFromPicture') || false;
			if (identifyOnPictureElement) identifyOnPictureElement.style.display = 'block';
			if (removeMeFromPictureElement) removeMeFromPictureElement.style.display = 'none';
			
		    for (var i=0; i<nameList.length;  i++) {
			    if (nameList[i][3]){
					 if (identifyOnPictureElement) identifyOnPictureElement.style.display = 'none';
					 if (removeMeFromPictureElement) removeMeFromPictureElement.style.display = 'block';
			    }
			    var name = document.createElement('div');
			    var link = document.createElement('a');
			    link.href = nameList[i][2]
			    link.appendChild(document.createTextNode(nameList[i][0]))
			    name.appendChild(link)		
			    // hide until we have the correct position, which we won't have until
			    // we have placed it in the container
			    name.style.visibility = 'hidden';
			    if (this.photoNames) {
				    this.photoNames.appendChild(name);
			    }

				// calculate the correct left position of the name
				var position = parseInt(nameList[i][1]);
				var width = name.offsetWidth;
				var left = position - (width / 2);
				// if the name would overflow to the left, we correct the left position
				var arrowOffset = 5;
				if (left < 0){
					left = position - arrowOffset;
					if (left < 0) left = position;
					name.className = 'left';
				}
				// similarly, if it overflows to the right, we correct the left position
				if ((left + name.offsetWidth) > name.parentNode.offsetWidth){
					left = position - name.offsetWidth + arrowOffset;
					if ((left + name.offsetWidth) > name.parentNode.offsetWidth) left = position - name.offsetWidth;
					name.className = 'right';
				}
				
				// set the corrected left position and show the name
			    name.style.left = left + "px"
			    name.style.visibility = 'visible';
		    }
		}
		
		
		if (this.currentTextEdit) this.currentTextEdit.focus();
	}
}

var mouseOverPhoto = {
    currentPhoto: null,
    move: function(sender, e, alignLeft) {
        if (this.currentPhoto == null) {
            return;
        }

        if (!e) e = window.event;
        this.currentPhoto.style.left = (e.clientX + (alignLeft ? -(31 + this.currentPhoto.childNodes[0].childNodes[0].width) : 10)) + 'px';
        if (this.currentPhoto.offsetHeight) {
            this.currentPhoto.style.top = (e.clientY - (this.currentPhoto.offsetHeight / 2) + 100) + 'px';
        }
        else if (this.currentPhoto.height) {
            this.currentPhoto.style.top = (e.clientY - (this.currentPhoto.height / 2) + 100) + 'px';
        }
        else {
            this.currentPhoto.style.top = (e.clientY + 10) + 'px';
        }
    },
    show: function(sender, e, id, imageUrl, caption, alignLeft) {
        this.hide();

        var senderPos = this.findPos(sender);

        var rootDiv = document.createElement('div');
        rootDiv.id = 'mouseOverPhoto_' + id.replace(/\-/gmi, '_');
        rootDiv.style.display = 'block';
        rootDiv.style.backgroundColor = 'White';
        rootDiv.style.border = '1px solid black';
        rootDiv.style.padding = '11px';
        rootDiv.style.position = 'absolute';
        rootDiv.style.zIndex = 100;
        sender.parentNode.parentNode.appendChild(rootDiv);
        this.currentPhoto = rootDiv;
        this.move(sender, e, alignLeft);

        var nextDiv = document.createElement('div');
        rootDiv.appendChild(nextDiv);

        var image = document.createElement('img');
        image.src = imageUrl;
        nextDiv.appendChild(image);

        if (caption) {
            var p = document.createElement('p');
            p.innerText = caption;
            nextDiv.appendChild(p);
        }
    },
    hide: function() {
        if (this.currentPhoto != null && this.currentPhoto.parentNode != null) {
            this.currentPhoto.parentNode.removeChild(this.currentPhoto);
        }
        this.currentPhoto = null;
    },
    findPos: function(obj) {
        var curleft = curtop = 0;
        if (obj.offsetParent) {
            do {
                curleft += obj.offsetLeft;
                curtop += obj.offsetTop;
            } while (obj = obj.offsetParent);
        }
        return [curleft, curtop];
    }
}

var displayPhoto = {
	show: function(id){
		document.getElementById(id).style.display = "block"
	},
	hide: function(id){
		document.getElementById(id).style.display = "none"
	}
}
var imgWidth=0;
this.imgHeight=0;
var imageTools = {
	x: 0,
	y: 0,
	l: 0,
	t: 0,
	w: 0,
	h: 0,
	cropTop: 0,
	cropRight: 0,
	cropBottom: 0,
	cropLeft: 0,
	ratio: 1.33333,
	imageTopInput: null,
	imageLeftInput: null,
	imageWidthInput: null,
	imageHeightInput: null,		
	init: function(imageLeftInputId, imageTopInputId, imageWidthInputId, imageHeightInputId, imgWidth, imgHeight) {		
		this.imgWidth = imgWidth;
		this.imgHeight = imgHeight;							
		
		this.canvas = document.getElementById('canvas');
		this.canvas.onmousedown = imageTools.mousedown;
		this.canvas.onmousemove = imageTools.mousemove;
		document.onmouseup = imageTools.mouseup;
		this.crop = document.getElementById('crop');
		this.cache = document.getElementById('cache');
		this.layers = document.getElementById('layers');
		
		imageTopInput = document.getElementById(imageTopInputId);
		imageLeftInput = document.getElementById(imageLeftInputId);
		imageWidthInput = document.getElementById(imageWidthInputId);
		imageHeightInput = document.getElementById(imageHeightInputId);		
		
		this.crop.style.height = this.crop.offsetHeight*this.ratio+'px';				

		this.crop.moveTo = imageTools.moveTo;
		this.crop.resizeTo = imageTools.resizeTo;
		
		var layer0 = document.createElement('div');
		layer0.id = 'layer0';
		layer0.style.position = 'absolute';
		layer0.style.zIndex = '1';
		layer0.style.width = this.cache.firstChild.width+'px';		
		layer0.style.height = this.cache.firstChild.height+'px';	

		layer0.style.backgroundImage = 'url('+this.cache.firstChild.src+')';
		layer0.style.overflow = "hidden";
		
		//layer0.style.opacity = '0.4';
		//layer0.style.filter = "alpha(opacity=30)";
		this.layers.appendChild(layer0);

		var layer1 = document.createElement('div');
		layer1.id = 'layer1';
		layer1.style.position = 'absolute';
		layer1.style.zIndex = '2';
		layer1.style.width = this.cache.firstChild.width+'px';
		layer1.style.height = this.cache.firstChild.height+'px';
		//layer1.style.backgroundImage = 'url('+this.cache.firstChild.src+')';
		layer1.style.clip = 'rect('+ px(this.crop.offsetTop+1,
										this.crop.offsetWidth-1+this.crop.offsetLeft,
										this.crop.offsetHeight-1+this.crop.offsetTop,
										this.crop.offsetLeft+1
			) +')';
		
		this.crop.imgWidth = imgWidth;			
		this.crop.imgHeight = imgHeight;	
			
		this.layers.appendChild(layer1);
		this.crop.l1 = this.layers.lastChild;

		this.crop.moveTo(parseInt(imageLeftInput.value), parseInt(imageTopInput.value));
		this.crop.resizeTo(parseInt(imageWidthInput.value), parseInt(imageHeightInput.value), 'se');
	},
	mousemove: function(e) {		
		if (window.event) var e = window.event;
		if (imageTools.target) {	
			var x = (window.event) ? window.event.x+document.body.scrollLeft : e.pageX;
			var y = (window.event) ? window.event.y+document.body.scrollTop : e.pageY;			
			x -= imageTools.x;
			y -= imageTools.y;			
	
			switch(imageTools.target.id) {
				case 'crop': {
					imageTools.crop.moveTo(x,y);
					break;
				}
				case 'cropNW': {
					imageTools.crop.resizeTo(x,y,'nw');
					break;
				}
				case 'cropNE': {
					imageTools.crop.resizeTo(x,y,'ne');
					break;
				}
				case 'cropSW': {
					imageTools.crop.resizeTo(x,y,'sw');
					break;
				}
				case 'cropSE': {
					imageTools.crop.resizeTo(x,y,'se');
					break;
				}
				default: {
					break;
				}
			}
			
			imageTools.xx = x
			imageTools.yy = y;
		}
	},
	mousedown: function(e) {
		if (window.event) var e = window.event;
		var target = e.target || e.srcElement;
		imageTools.target = target;
		
		var x = (window.event) ? window.event.x+document.body.scrollLeft : e.pageX;
		var y = (window.event) ? window.event.y+document.body.scrollTop : e.pageY;
		imageTools.x = x;
		imageTools.y = y;

		imageTools.xx = 0
		imageTools.yy = 0;
		
		if (target.id.indexOf('crop') != -1) {
			imageTools.l = imageTools.crop.offsetLeft;
			imageTools.t = imageTools.crop.offsetTop;
			imageTools.w = imageTools.crop.offsetWidth;
			imageTools.h = imageTools.crop.offsetHeight;
		}
		
		imageTools.mousemove(e);
	},
	mouseup: function(e) {
		imageTools.target = false;				
		imageTopInput.value = imageTools.crop.offsetTop;
		imageLeftInput.value = imageTools.crop.offsetLeft;
		imageWidthInput.value = parseInt(imageTools.crop.style.width);
		imageHeightInput.value = parseInt(imageTools.crop.style.height);
	},
	moveTo: function(x,y) {							
		        
        
        if((x+imageTools.l + this.offsetWidth-1) >= this.imgWidth)
            this.style.left = (this.imgWidth-this.offsetWidth-1) +'px';
        else
            this.style.left = (x+imageTools.l+1 > 0) ? x+imageTools.l+'px' : '0px';		
            
        if((y+imageTools.t+this.offsetHeight-1) >= this.imgHeight)
            this.style.top = this.imgHeight-this.offsetHeight-1+'px';                
        else            
            this.style.top = (y+imageTools.t+1 > 0) ? y+imageTools.t+'px' : '0px';    		
				
		this.l1.style.clip = 'rect('+ px(this.offsetTop+1,this.offsetWidth-1+this.offsetLeft,this.offsetHeight-1+this.offsetTop,this.offsetLeft+1)+')';
	},
	resizeTo: function(x,y,direction) {		
		minSizeX = 30;
		minSizeY = (imageTools.ratio) ? Math.round(minSizeX*imageTools.ratio) : minSizeX;
		
		maxSizeX = this.Width;
		maxSizeY = this.Height;

		switch(direction) {
			case 'nw': {
				if (imageTools.ratio) y = x*imageTools.ratio;
				
				if ((y*-1)+imageTools.h-2 > minSizeY && y+imageTools.t+1 > 0) {				
					this.style.top = (y+imageTools.t > 0) ? y+imageTools.t+'px' : '0px';															
					this.style.height = ((y*-1)+imageTools.h > minSizeY) ? (y*-1)+imageTools.h-2+'px' : minSizeY+'px';					
				}
				if ((x*-1)+imageTools.w-2 > minSizeX && (x+imageTools.l+1 > 0)) {
					if (imageTools.ratio) {
						if (y+imageTools.t+1 > 0) {
							this.style.left = (x+imageTools.l > 0) ? x+imageTools.l+'px' : '0px';
							this.style.width = ((x*-1)+imageTools.w > minSizeX) ? (x*-1)+imageTools.w-2+'px' : minSizeX+'px';
						}
					}
					else {
						this.style.left = (x+imageTools.l > 0) ? x+imageTools.l+'px' : '0px';
						this.style.width = ((x*-1)+imageTools.w > minSizeX) ? (x*-1)+imageTools.w-2+'px' : minSizeX+'px';					
					}
				}
				this.l1.style.clip = 'rect('+ px(this.offsetTop+1,this.offsetWidth+this.offsetLeft-1,this.offsetHeight+this.offsetTop-1,this.offsetLeft+1)+')';
				break;
			}
			case 'ne': {			    
			    leftover = this.imgWidth- (x+imageTools.w) - this.offsetLeft+1;			    			    
			    if(leftover < 0)
			    {				   
				    break;			    
				 }
				if (imageTools.ratio) y = (x*-1)*imageTools.ratio;
				
				if ((y*-1)+imageTools.h-2 > minSizeY && (y+imageTools.t+1 > 0)) {					
					this.style.top = (y+imageTools.t > 0) ? y+imageTools.t+'px' : '0px';
					this.style.height = ((y*-1)+imageTools.h > minSizeY) ? (y*-1)+imageTools.h-2+'px' : minSizeY+'px';
				}
				if (imageTools.ratio) {
					if (y+imageTools.t+1 > 0) 
					{						
						this.style.width = (x+imageTools.w-2 > minSizeX) ? x+imageTools.w-2+'px' : minSizeX+'px';					
						this.l1.style.clip = 'rect('+ px(this.offsetTop+1,this.offsetWidth+this.offsetLeft-1,this.offsetHeight+this.offsetTop-1,this.offsetLeft+1)+')';
					}
				}
				else {
					this.style.width = (x+imageTools.w-2 > minSizeX) ? x+imageTools.w-2+'px' : minSizeX+'px';
					this.l1.style.clip = 'rect('+ px(this.offsetTop+1,this.offsetWidth+this.offsetLeft-1,this.offsetHeight+this.offsetTop-1,this.offsetLeft+1)+')';
				}
				break;
			}
			case 'sw': {
																																								
				if(imageTools.t+ this.offsetHeight >= this.imgHeight-1)
				    break;												
				
				if (imageTools.ratio) y = (x*imageTools.ratio)*-1;				
				
				
				if ((x*-1)+imageTools.w > minSizeX) {
					this.style.left = (x+imageTools.l > 0) ? x+imageTools.l+'px' : '0px';
					this.style.width = ((x*-1)+imageTools.w-2 > minSizeX) ? (x*-1)+imageTools.w-2+'px' : minSizeX+'px';
				}
				else {}
				this.style.height = (y+imageTools.h-2 > minSizeY) ? y+imageTools.h-2+'px' : minSizeY+'px';
				this.l1.style.clip = 'rect('+ px(this.offsetTop+1,this.offsetWidth+this.offsetLeft-1,this.offsetHeight+this.offsetTop-1,this.offsetLeft+1)+')';
				break;
			}
			case 'se': 
			{
			    if((imageTools.t+ this.offsetHeight)+2 > this.imgHeight)
			    {			       			        
			        return;
			    }
				 
				    
				if(imageTools.l+ this.offsetWidth >= this.imgWidth)
				{				   			       
			       return;
			    }
			
				if (imageTools.ratio) y = Math.round(x*imageTools.ratio);

				this.style.width = (x+imageTools.w-2 > minSizeX) ? x+imageTools.w-2+'px' : minSizeX+'px';
				this.style.height = (y+imageTools.h-2 > minSizeY) ? y+imageTools.h-2+'px' : minSizeY+'px';
				this.l1.style.clip = 'rect('+ px(this.offsetTop+1,this.offsetWidth+this.offsetLeft-1,this.offsetHeight+this.offsetTop-1,this.offsetLeft+1)+')';
				break;
			}
			default: {
				break;
			}
		}
	}
}

function px(){
	var str = '';
	for (var i=0; i<arguments.length; i++) {
		str += (i<arguments.length-1) ? arguments[i]+'px ' : arguments[i]+'px';
	}
	return str;
}

function sendFlirt(type){
	// do something with type
	self.close();
}


/** ADDED BY ALLAN **/
function getValues(friendsGroup, favoritesGroup){
    var isFirst = true;
    var str = '';
    var friends = document.getElementsByName(friendsGroup);
    var favorites = document.getElementsByName(favoritesGroup);
    if ( friends != null ){
        for ( i=0; i < friends.length; i++ ){
            if ( friends[i].checked == true ){
                if (friends[i].value != 'on'){
                    if (isFirst == false){
                        str = str + ';';
                    }
                    else{
                        isFirst = false;
                    }
                    str = str + friends[i].value;
                }
            }
        }
    }
    if ( favorites != null ){
        for ( i=0; i < favorites.length; i++ ){
            if ( favorites[i].checked == true ){
                if (favorites[i].value != 'on'){ 
                    if (isFirst == false){
                        str = str + ';';
                    }
                    else{
                        isFirst = false;
                    }
                    str = str + favorites[i].value;
                }
            }
        }
    }
    return str;
}        
/******************/

function getHref()
{
    return document.location.href;
}
