function getScrollPosition()

{

	var hscroll = f_scrollLeft();

	var vscroll = f_scrollTop();

	

	return [hscroll, vscroll];

}
function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

function setAttributValue(id, attribute, value)

{

	eval("document.getElementById('"+id+"')."+attribute+" = '" + value + "'");

}

function getStyle(el, style) {

   if(!document.getElementById) return;

   

     var value = el.style[toCamelCase(style)];

   

    if(!value)

        if(document.defaultView)

            value = document.defaultView.

                 getComputedStyle(el, "").getPropertyValue(style);

       

        else if(el.currentStyle)

            value = el.currentStyle[toCamelCase(style)];

     

     return value;

}



function setStyle(objId, style, value) {

    document.getElementById(objId).style[style] = value;

}



function toCamelCase( sInput ) {

    var oStringList = sInput.split('-');

    if(oStringList.length == 1)   

        return oStringList[0];

    var ret = sInput.indexOf("-") == 0 ?

       oStringList[0].charAt(0).toUpperCase() + oStringList[0].substring(1) : oStringList[0];

    for(var i = 1, len = oStringList.length; i < len; i++){

        var s = oStringList[i];

        ret += s.charAt(0).toUpperCase() + s.substring(1)

    }

    return ret;

}



function increaseWidth(addToWidth, whichDiv){

    var theDiv = document.getElementById(whichDiv);

    var currWidth = parseInt(getStyle(theDiv, "width"));

    var newWidth = currWidth + parseInt(addToWidth);

    setStyle(whichDiv, "width", newWidth + "px");

}

function getPageSize()

{
	var pageWidth = f_clientWidth();
	var pageHeight = f_clientHeight();

	return [pageWidth,pageHeight];

}

function getWindowSize() {

  var myWidth = 0, myHeight = 0;

  if( typeof( window.innerWidth ) == 'number' ) {

    //Non-IE

    myWidth = window.innerWidth;

    myHeight = window.innerHeight;

  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {

    //IE 6+ in 'standards compliant mode'

    myWidth = document.documentElement.clientWidth;

    myHeight = document.documentElement.clientHeight;

  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {

    //IE 4 compatible

    myWidth = document.body.clientWidth;

    myHeight = document.body.clientHeight;

  }

	return [myWidth,myHeight];  

}

function centerWindow( object )

{

	container = $(object);

	var size = getWindowSize();

	var spos = getScrollPosition();


	var width  = container.getWidth();

	var height = container.getHeight();
	

	container.style.top = ((((size[1] - Math.round(height))/2)+23) +spos[1]) + "px";

	container.style.left  = ((((size[0] - Math.round(width))/2) + spos[0])+23) + "px";

}

function setOverlayHeight() 

{

	var div = document.getElementById('TB_overlay');

	var pageSize = getPageSize();

	div.style.height = pageSize[1] + "px";

}



function showOverlay ( )

{

	document.getElementById('TB_overlay').style.display = '';

}



function showWindow(windowId)

{

	document.getElementById(windowId).style.display = '';

}



function hideOverlay()

{

	document.getElementById('TB_overlay').style.display = 'none';	

}



function hideWindow(windowId)

{

	document.getElementById(windowId).style.display = 'none';

}



function loadFormLayer ( resp, object )

{

	toggleFlashObjects('close');

	ElementStateChanged (resp, object );

	showOverlay();

	centerWindow( object )		

	showWindow(object);

	setOverlayHeight();

}

function closeFormLayer ( object )

{

	toggleFlashObjects('open');

	hideOverlay();

	hideWindow(object);

	document.getElementById(object).innerHTML = '';		

}

function customFormLayer( in_url, in_callback , in_method , in_container_id, in_style_array, in_center)

{

	container = document.getElementById(in_container_id);

	for(var key in in_style_array)

	{

		if(key != 'toJSONString')

		{	

			eval("container.style." + key + " = '" + in_style_array[key] + "'");

		}

	}

	SimpleAJAXCall(in_url, in_callback, in_method, in_container_id);

}

function verifyText(textareaObject, text)

{

	

	if(textareaObject.value == text)

		textareaObject.value = '';

	

	return true;

}



function cleanInnerHTML(response, elementId)

{

	document.getElementById(elementId).innerHTML = '';

}



function doNothing()

{

}



function displayLoading(elementId)

{

	

	if((typeof document.getElementById(elementId) != 'undefined') && (elementId != ''))

	{

		if(elementId == 'window2')

		{

			showOverlay();

			showWindow(elementId);

		}

		document.getElementById(elementId).innerHTML = '<img src="images/loading.gif" style="margin:0 auto" />';

	}

}

function toggleFlashObjects()

{

	var elements = document.getElementsByTagName("embed");

	var length   = elements.length;

	for(i=0;i<length;i++)

	{

		if(elements[i].style.display == '')

		{

			elements[i].style.display = 'none';

		}

		else

		{

			elements[i].style.display = ''

		}

	}

}

function switchState(principalObj, secondaryObjId)

{

	principalObj.style.display = 'none';

	document.getElementById(secondaryObjId).style.display = '';

	document.getElementById(secondaryObjId).focus();

}

function saveStates(form, object, enter)

{

	var elements = form.elements;

	for(i=0; i<elements.length; i++)

	{

		if(((elements[i].type == 'text') && (elements[i] != object)) || (enter))

		{

			if(elements[i].title != '')

			{

				document.getElementById('span'+elements[i].title).innerHTML = elements[i].value;

				switchState(elements[i], 'span'+elements[i].title);

				if((enter) && (elements[i] == object))

					SimpleAJAXCall ( 'index.php?country.controller/update/'+elements[i].title+'/'+object.value, doNothing, 'GET', '' );

				

			}

		}

		else

		{

			if(elements[i].type == 'text')

			{

				SimpleAJAXCall ( 'index.php?country.controller/update/'+elements[i].title+'/'+elements[i].value, doNothing, 'GET', '' );

			}

		}

	}

}

function checkEnter(e, form, object){ //e is event object passed from function invocation

	var characterCode; //literal character code will be stored in this variable

	

	if(e && e.which){ //if which property of event object is supported (NN4)

		e = e;

		characterCode = e.which; //character code is contained in NN4's which property

	}

	else{

		e = event;

		characterCode = e.keyCode; //character code is contained in IE's keyCode property

	}

	

	if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)

		saveStates(form, object, true);

	}

}

function submitForm(formId)

{

	document.getElementById(formId).submit();

}

function toggleObject(objectId)

{

	var target = document.getElementById(objectId);

	if(target.style.display == 'none')

		showWindow(objectId);

	else

		hideWindow(objectId);

}

function changePartner (num)

{

	var length = $('sociosContainer').childElements().length;

	if((num - 1) == length)

		num = 1;

	$('partnerImg').fade({ afterFinish: function(){

	   $('partnerImg').src = $('sociosContainer').childElements()[num - 1].innerHTML;



       $('partnerImg').appear();



	new PeriodicalExecuter(function (pe) { 

		changePartner(num + 1);

		pe.stop();

		}, 

		5);

     }

   }); 

	

}

document.observe("dom:loaded", function() { 

		if($('partnerImg'))

		{

			$('partnerImg').appear();

			 new PeriodicalExecuter(function (pe) { 

				changePartner(1);

				pe.stop();

			 }, 

			 5);

		}

	});

var zwindow = "";

function openwin(number, name)

{

	var size = getWindowSize();

	/*var top  = ((size[1] - (size[1]-60)) / 2);

	var left = ((size[0] - 990) / 2);

	size[0] = 900;

	*/

	var top = 0;

	var left = 0;

	size[1] = size[1] + 62;

	size[0] = size[0] - 19;



	zwindow=dhtmlwindow.open("id", "iframe", "http://viewer.zmags.com/publication/"+number, name, "width="+size[0]+"px,height="+(size[1]-97)+"px,resize=1,scrolling=1,center=0,top="+top+",left="+left, "");

}

function setLinkValue(prefix, inputId, url)

{

	url 	= url.replace(/prefix/, '');

	url 	= prefix + url;

	document.getElementById(inputId).value = url;

	closeFormLayer('window2');

}

function createSortable (containerId)

{

	Sortable.create(containerId, {

		tag:'li',

		ghosting:false,

		constraint:false,

		hoverclass:'over',

		onUpdate:function(sortable){

			var form = document.getElementById('serializeForm');

			form.serializedArray.value = Sortable.serialize(sortable);

		}

	});

}

function createSortablePopup (resp, windowId, containerId)

{

	loadFormLayer(resp, windowId);

	createSortable(containerId);

}

function onEndCrop( coords, dimensions ) {

	$('sourceXY').value = coords.x1 + ',' + coords.y1;

	$('size').value 	= dimensions.width + ',' + dimensions.height;

}



// with a supplied ratio

function createCropper(ratioX, ratioY) { 

	new Cropper.Img( 

		'imagen', 

		{ 

			ratioDim: { x: ratioX, y: ratioY }, 

			displayOnInit: true, 

			onEndCrop: onEndCrop,

			previewWrap: 'previewArea'

		} 

	) 

}

function createCropperPopup (resp, windowId, xy)

{

	loadFormLayer(resp, windowId);

	size = xy.split('x');

	createCropper(size[0], size[1]);

}

function deleteAlbum(id)

{

	javascript:showWindow('msgbox'); 

	document.getElementById('deleteLink').href = 'index.php?publish.controller/delete_albums/' + id + '';

	return false;

}

function deletePhoto(id)

{

	javascript:showWindow('msgbox2'); 

	document.getElementById('deleteLinkview').href = 'index.php?publish.controller/delete_photos/' + id + '';

	return false;

}
document.observe('dom:loaded', function () {
	if($('window3'))
	{
		centerWindow('window3');
	}
});

function moveDialecticaHome(id)
{
	var duration = 0.5,slideWidth = 749;
	var total = slideWidth * id;
	
	$$('.selected').each(function (item) {
		item.className='';
	});
	var nameclass = 'IT_'+id;
	document.getElementById(nameclass).className = 'selected';
	
	container2 	 = $$('#stage-gallery')[0];
	new Effect.Morph(container2, {
		duration: duration,
		style: 'left:-'+total+'px'
	});
}
