var rand;
function showImage(swfobj, e){
	thisMovie(swfobj).CallImageLoader(e);
}
function enviarComment ( frm ){
	frm.action = home+'/comments/add/'+frm['data[Comment][blog_id]'].value;
	if(!IsEmail(frm['data[Comment][email]'],"No es un email valido")){
		return false;	
	}
	return true;	

}
function playanimation (){
	/* aca el background se esconde y muestra seccion*/
	var DivRef = document.getElementById('wrapper');
	if(DivRef.style.display!="block"||DivRef.style.display!="none")
	{
		document.getElementById('wrapper').style.display = 'none';
		document.getElementById('wrapped-body').style.background = 'url('+home+'/img/bg000.jpg)';
		document.getElementById('boton-middle').style.display = 'block';
		document.getElementById('click_here').innerHTML = "CLICK HERE";
	}
}
function showAll(){
	var DivRef = document.getElementById('wrapper');
	if(DivRef.style.display=="none")
	{
		document.getElementById('wrapper').style.display = 'block';	
		document.getElementById('boton-middle').style.display = 'none';
		document.getElementById('wrapped-body').style.background = 'url('+home+'/img/'+backgrounds[rand]+')';
	}
}
function changeBackground (){
	rand = Math.floor(Math.random()*backgrounds.length-1)+1;
	document.getElementById('wrapped-body').style.background = 'url('+home+'/img/gallery/'+backgrounds[rand]+')';
	var pars = "&bgfile="+backgrounds[rand]+"&";
	new Ajax.Request ( home+'/change/background/', {
								  method: 'get',
								  parameters: pars
								  });
	
}
function showCommentDiv (e){
	var DivRef = document.getElementById('layerComment'+e);
	if(DivRef.style.display!="block")
	{
	DivRef.style.display = "block";
	}else{
	DivRef.style.display = "none";
	}


	
}
function showCommentBox(e){
	var DivRef = document.getElementById('layerComment');
	if(DivRef.style.display!="block")
	{
	    document.location.href = '#home';
		document.getElementById('commentID').value = e;
		document.getElementById('layerComment').style.display = "block";		
		document.getElementById('loginLayerShim').style.display = "block";		
		document.frmcomment['data[Comment][username]'].value = '';
		document.frmcomment['data[Comment][email]'].value = '';
		document.frmcomment['data[Comment][website]'].value = '';
		document.frmcomment['data[Comment][body]'].value = '';		

		
	}else{
		document.getElementById('loginLayerShim').style.display = "none";		
		document.getElementById('layerComment').style.display = "none";	
	}
	
}
function showGalleryBox(e)
{
	var DivRef = document.getElementById('randomLayer');
	if(DivRef.style.display!="block")
	{
	var fswf = new SWFObject(home+'/swf/pre-portfolio.swf', 'portfolio', '630', '377', '8');
		if(home!=''){
		fswf.addVariable("flashVarText","&local=/blog/");		
		}
		fswf.addParam("wmode", "transparent");	
		fswf.write("randomLayer");
		document.getElementById('randomLayer').style.display = "block";		
		document.getElementById('wrapper').style.display = 'none';
		document.getElementById('wrapped-body').style.background = 'url('+home+'/img/random/fondo_pre_random.jpg)';
//		document.getElementById('loginLayerShim').style.display = "block";		
//		window.work.resetScroll();
		// aca mostrar el flash
		
		
	}else{
		document.getElementById('wrapper').style.display = 'block';
		document.getElementById('wrapped-body').style.background = 'url('+home+'/img/'+backgrounds[rand]+')';
		document.getElementById('loginLayerShim').style.display = "none";		
		document.getElementById('randomLayer').style.display = "none";	
	}
}
function thisMovie(movieName) {
        if (navigator.appName.indexOf("Microsoft") != -1) {
          return window[movieName];
        } else {
          return document[movieName];
        }
}
function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
   var arVersion = navigator.appVersion.split("MSIE")
   var version = parseFloat(arVersion[1])
   if ((version >= 5.5) && (document.body.filters)) 
   {
      for(var i=0; i<document.images.length; i++)
      {
         var img = document.images[i]
         var imgName = img.src.toUpperCase()
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
         {
            var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgStyle = "display:inline-block;" + img.style.cssText 
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\', sizingMethod='fit');\"></span>" 
            img.outerHTML = strNewHTML
            i = i-1
         }
      }
   }    
}
function addListener(Obj, event, eventHandler) {

    if( Obj.addEventListener ) {
        Obj.addEventListener(event, eventHandler, false);
    } else if( Obj.attachEvent ) {
        Obj.attachEvent("on"+event, eventHandler);
    }
}
if(!document.getElementById&&document.all){
        document.getElementById=function(id){
        return document.all[id];
        };
}
var _preloaded = null;
function preload(preload) {
	_preloaded = [];
	for(var i = 0, l = preload.length; i < l; i++) {
		_preloaded[i] = document.createElement("img");
		_preloaded[i].src = preload[i];
	}
}
function swapImg(evt, newImg, imgId) {
	newImg = home+'/img/'+newImg;
	var dst = imgId ? document.getElementById(imgId) : (evt.srcElement || evt.target);
	dst.src = typeof(newImg) == "number" ? _preloaded[newImg].src : newImg;
}
var win= null;
function openNewWindow(mypage,w,h,myname,scrollb){
	var winl = (screen.width-w)/2;
	var wint = (screen.height-h)/2;
	settings='height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scrollb+',toolbar=no,location=no,status=no,menubar=no,resizable=no,dependent=no'
	win=window.open(mypage,myname,settings)
	if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
}
// Trim Function
function Trim(TRIM_VALUE)
{
	if(TRIM_VALUE.length < 1)
	{
		return"";
	}
	TRIM_VALUE = RTrim(TRIM_VALUE);
	TRIM_VALUE = LTrim(TRIM_VALUE);
	if(TRIM_VALUE=="")
	{
		return "";
	}
	else
	{
		return TRIM_VALUE;
	}
}
//Right Trim Function
function LTrim(VALUE)
{
	var w_space = String.fromCharCode(32);
	if(v_length < 1)
	{
		return"";
	}
	var v_length = VALUE.length;
	var strTemp = "";
	var iTemp = 0;

	while(iTemp < v_length)
	{
		if(VALUE.charAt(iTemp) == w_space)
		{
		}
		else
		{
			strTemp = VALUE.substring(iTemp,v_length);
			break;
		}
		iTemp = iTemp + 1;
	}
	return strTemp;
}
// Right Trim Function
function RTrim(VALUE)
{
	var w_space = String.fromCharCode(32);
	var v_length = VALUE.length;
	var strTemp = "";
	if(v_length < 0)
	{
		return"";
	}
	var iTemp = v_length -1;

	while(iTemp > -1)
	{
		if(VALUE.charAt(iTemp) == w_space)
		{
		}
		else
		{
			strTemp = VALUE.substring(0,iTemp +1);
			break;
		}
		iTemp = iTemp-1;

	}
	return strTemp;
}
// To Validate the Email
function IsEmail(obj, msgstr)
{
	if(Trim(obj.value) == "")
	{
		alert(msgstr);
		obj.focus();
		return false;
	}
	else
	{
	    if(obj.value.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
    	    return true;
	    else
		{
			alert(msgstr);
			obj.focus();
    	    return false;
		}
	}
}
function init()
{
	rand = 2;
	if(document.getElementById('boton-middle')){
		document.getElementById('boton-middle').style.display = 'none';
	}
	if(document.getElementById('flashportfolio')){
		document.getElementById('flashportfolio').style.display = 'none';
	}
	var arr = new Array(home+'/img/random/bg_portfolio.jpg',home+'/img/random/fondo_pre_random.jpg',home+'/img/submit-comment.gif',home+'/img/submit-comment.gif','thnkx.gif', home+'/img/bg-comment-form.gif',home+'/img/random/01.jpg',home+'/img/random/02.jpg',home+'/img/random/03.jpg',home+'/img/random/04.jpg',home+'/img/random/05.jpg',home+'/img/random/06.jpg',home+'/img/random/07.jpg',home+'/img/random/08.jpg',home+'/img/random/09.jpg');
	preload (arr);

}
function onPageUnload (){}
addListener( window, "load", init);