
var siteUrl = 'http://beta2.mymessenger.se';

function toggleModule(module_div,module_arrow) {

	if ( module_arrow.src == siteUrl + '/images/pil_v_02.gif' ) {
		Effect.BlindUp(module_div); 
		module_arrow.src='/images/pil_v_01.gif';	
	} else {
		Effect.BlindDown(module_div); 
		module_arrow.src='/images/pil_v_02.gif';	
	}
}

function toggleModuleB(module_div,module_arrow) {

	if ( module_arrow.src == siteUrl + '/images/pil_b_02.gif' ) {
		Effect.BlindUp(module_div); 
		module_arrow.src='/images/pil_b_01.gif';	
	} else {
		Effect.BlindDown(module_div); 
		module_arrow.src='/images/pil_b_02.gif';	
	}
}

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";}


function tagImage(image_id,x1,x2,y1,y2,friend_id,name,email,account_id) {
	tagFormDiv.style.display='none';

	var f_id = getCheckedValue(friend_id);

	new Ajax.Request('/functions__tag-real-image.php?i=' + image_id + '&f=' + f_id + '&name=' + name.value + '&email=' + email.value + '&x1=' + x1.value + '&x2=' + x2.value + '&y1=' + y1.value + '&y2=' + y2.value,
		{
		method: 'get',
		onSuccess: function(transport){       
			var response = transport.responseText;
		},
		onFailure: function(){ 
			alert('Something went wrong...');
		} 
	});

	new Ajax.Updater('m_image', '/ajax/load_module.php?module=m_image&a1=' + account_id + '&a2=' + image_id + '&a3=1', { method: 'get' });	
	new Ajax.Updater('m_image', '/ajax/load_module.php?module=m_image&a1=' + account_id + '&a2=' + image_id + '&a3=1', { method: 'get' });	
}	

function ajax_postgb(content,button,account_id) {	
	button.disabled = true;
	content.disabled = true;
	new Ajax.Request('/functions__guestbook_write.php?aid=' + account_id.value +'&content=' + content.value, 
		{
		method: 'get',
		onSuccess: function(transport){       
			var response = transport.responseText;
		},
		onFailure: function(){ 
			alert('Something went wrong...');
		} 
	});

	button.disabled = false;
	content.disabled = false;
}

function ajax_rotate_image(account_id,image_id,rotate) {	

	alert(account_id + ' ' + image_id + ' ' + rotate);

	new Ajax.Request('/functions__rotate_image.php?aid=' + account_id +'&image_id=' + image_id + '&r=' + rotate, 
		{
		method: 'get',
		onSuccess: function(transport){       
			var response = transport.responseText;
		},
		onFailure: function(){ 
			alert('Something went wrong...');
		} 
	});

	new Ajax.Updater('m_image', '/ajax/load_module.php?module=m_image&a1=' + account_id + '&a2=' + image_id + '&a3=0', { method: 'get' });	
	new Ajax.Updater('m_image', '/ajax/load_module.php?module=m_image&a1=' + account_id + '&a2=' + image_id + '&a3=0', { method: 'get' });	
}

function ajax_postib(content,button,account_id,image_id) {	
	button.disabled = true;
	content.disabled = true;
	new Ajax.Request('/functions__imagebook_write.php?aid=' + account_id.value +'&content=' + content.value + '&image_id=' + image_id.value, 
		{
		method: 'get',
		onSuccess: function(transport){       
			var response = transport.responseText;
		},
		onFailure: function(){ 
			alert('Something went wrong...');
		} 
	});

	new Ajax.Updater('m_user_imagebook_preview', '/ajax/load_module.php?module=m_user_imagebook_preview&a1=' + account_id.value + '&a2=' + image_id.value + '&a3=999', { method: 'get' });	
	new Ajax.Updater('m_user_imagebook_preview', '/ajax/load_module.php?module=m_user_imagebook_preview&a1=' + account_id.value + '&a2=' + image_id.value + '&a3=999', { method: 'get' });	
	button.disabled = false;
	content.disabled = false;
}

function findTag(imageId) {
	var coors = findPos(imageId);
	var cursor = getPosition();

	var real_top = cursor.y;
	var real_left = cursor.x;

	// get tags
	var tag_count = document.getElementById('tagCount').value;

	for ( i=0 ; i < tag_count ; i++ ) {

		var tag_data = document.getElementById('tag_' + i).value;
		var tag_arr = tag_data.split(";");	
		var tag_left = parseInt(tag_arr[0]) + coors[0];
		var tag_top = parseInt(tag_arr[1]) + coors[1];

		var tag_user = tag_arr[4];
	
		var tag_right = tag_left + 125;
		var tag_bottom = tag_top + 125;
	
		if (tag_left < real_left && real_left < tag_right) {
			if (tag_top < real_top && real_top < tag_bottom) {
				var x = document.getElementById('taglayer_' + i);
				x.style.top = tag_top + 'px';
				x.style.left = tag_left + 'px';
				x.style.display = 'block';
				x.innerHTML = tag_user;
			}
		} else {
			var x = document.getElementById('taglayer_' + i);
			x.style.display = 'none';
		}
	}

	
}

function showTag(i,imageId) {
		var coors = findPos(imageId);


		// get tags
		var tag_data = document.getElementById('tag_' + i).value;
		var tag_arr = tag_data.split(";");	
		var tag_left = parseInt(tag_arr[0]) + coors[0];
		var tag_top = parseInt(tag_arr[1]) + coors[1];


		var tag_user = tag_arr[4];
	
		var tag_right = tag_left + 125;
		var tag_bottom = tag_top + 125;

		var y = document.getElementById('tagborder_' + i);
		y.style.display = 'block';
		y.style.top = tag_top + 'px';
		y.style.left = tag_left + 'px';
		y.style.width = '125px';
		y.style.height = '125px';
		y.innerHTML = '&nbsp;';


}


function hideTag(i) {
		var x = document.getElementById('taglayer_' + i);
		x.style.display = 'none';

		var y = document.getElementById('tagborder_' + i);
		y.style.display = 'none';

}


function getPosition(e) {
    e = e || window.event;
    var cursor = {x:0, y:0};
    if (e.pageX || e.pageY) {
        cursor.x = e.pageX;
        cursor.y = e.pageY;
    } 
    else {
        var de = document.documentElement;
        var b = document.body;
        cursor.x = e.clientX + 
            (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
        cursor.y = e.clientY + 
            (de.scrollTop || b.scrollTop) - (de.clientTop || 0);
    }
    return cursor;
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

	

