var showing = 0;

function show_search() {
    if(showing == 1) {
        Effect.SlideUp('search_box');
        showing = 0; 
    } else {
        $('search_box').clonePosition($('search_pulldown'));
        $('search_box').style.height = '265px';
        ary = $('search_box').style.top.split('px');
        var tp = parseInt(ary[0]) + 23;
        $('search_box').style.top = tp + 'px';
        var ary = $('search_box').style.left.split('px');
        var lt = parseInt(ary[0]) + 7;
        $('search_box').style.left = lt + 'px';
        Effect.SlideDown('search_box');
        showing = 1;
    }
}

function select_all(elem) {
    elem.select();
}


var Lightbox = Class.create({
	initialize : function(containerDiv) {
    	this.container = containerDiv;
		this._hideLayer(this.container);
	},
    _hideLayer : function hideLayer(userAction){
        $(userAction).style.display="none";
	},	
    _makeVisible : function makeVisible(){        
        if($('bg_fade') == null) {
            shade = new Element('div', {'id': 'bg_fade','style': 'visibility=hidden;'});
            document.body.appendChild(shade);
		}
        $("bg_fade").style.position = 'absolute';
        $("bg_fade").style.backgroundColor = '#000000';
        $("bg_fade").style.height = '150%';
        //$("bg_fade").style.display = 'block';
        $("bg_fade").style.zIndex = '5';
        $("bg_fade").style.top = 0;
        $("bg_fade").style.left = 0;
        $("bg_fade").setOpacity(0.5);
		$("bg_fade").style.visibility="visible";
		$("bg_fade").style.height='101%';
        $("bg_fade").style.width='101%';        
	},	_makeInvisible : function makeInvisible(){
        $("bg_fade").setOpacity(0);
		$("bg_fade").style.visibility="hidden";
		$("bg_fade").style.height='2px';
	},	_showLayer : function showLayer(userAction){
        x = window.screen.width;
        y = window.screen.height;
        var y = y / 2;
        var x = x / 2;
        var t = $(userAction).getDimensions();
        x = x - (t.width / 2);
        //alert(y + ' - ' + t.height);
        y = (y - (t.height / 2)) - 75;
        //alert(x + ' - ' + y);        
        /**switched main styling to css file.
        $(userAction).style.top = y + 'px';
        $(userAction).style.left = x + 'px';
        $(userAction).style.zIndex = '10';*/
        $(userAction).style.display="block";
	},	_hideLayer : function hideLayer(userAction){
        $(userAction).style.display="none";
	},	_fade : function fadeBg(userAction,whichDiv){
        if(userAction=='close'){
            new Effect.Opacity('bg_fade',
			   {duration:.5,
                from:0.5,
                to:0,
                afterFinish:this._makeInvisible(),
                afterUpdate:this._hideLayer(whichDiv)});
		}else{
            new Effect.Opacity('bg_fade',
               {duration:.5,
                from:0,
                to:0.5,
                beforeUpdate:this._makeVisible(),
                afterFinish:this._showLayer(whichDiv)});
		}	
    },	open : function () {
        this._fade('open', this.container);
	},	close : function () {
    	this._fade('close', this.container);
	}
});



var test;
Event.observe(window, 'load', function () {
    test = new Lightbox('containerDiv');
        
});

function show_login() {
    test.open();
    return false;
}

function hide_login() {
    test.close();
    return false;
}

function in_arrays(needle,haystack) {
 var i1;
 for(i1 = 0;i1 < haystack.length;i1++) {
  //alert('in_arrays ' + haystack[i1] + ' - ' + needle);
  if(needle == haystack[i1]) {
   return true;
  }
 }
 return false;
}

var positioned_badge = Array();

function show_badge_description(badge_id,a_tag) {
    if(!in_arrays(badge_id,positioned_badge)) {
        var t = Element.getDimensions('badge_desc_' + badge_id)
        $('badge_desc_' + badge_id).clonePosition(a_tag);
        $('badge_desc_' + badge_id).style.height = t.height;
        $('badge_desc_' + badge_id).style.width = t.width
        ary = $('badge_desc_' + badge_id).style.top.split('px');    
        var tp = parseInt(ary[0]) - t.height;        
        ary2 = $('badge_desc_' + badge_id).style.left.split('px');    
        var lt = parseInt(ary2[0]) - (t.width/2);
        tp -= 4;
        lt += 7;
        $('badge_desc_' + badge_id).style.top = tp + 'px';
        $('badge_desc_' + badge_id).style.left = lt + 'px';
        $('badge_desc_' + badge_id).style.display = "";
        positioned_badge[positioned_badge.length] = badge_id;
    } else {
        $('badge_desc_' + badge_id).style.display = "";
    }
}

function hide_badge_description(badge_id,a_tag) {
    $('badge_desc_' + badge_id).style.display = "none";
}


var positioned_cat = Array();

function show_cat_description(cat_id,a_tag) {
    if(!in_arrays(cat_id,positioned_cat)) {
        var t = Element.getDimensions('cat_desc_' + cat_id)
        $('cat_desc_' + cat_id).clonePosition(a_tag);
        $('cat_desc_' + cat_id).style.height = t.height;
        $('cat_desc_' + cat_id).style.width = t.width
        ary = $('cat_desc_' + cat_id).style.top.split('px');    
        var tp = parseInt(ary[0]) - t.height;
        tp += 10;        
        ary2 = $('cat_desc_' + cat_id).style.left.split('px');    
        var lt = parseInt(ary2[0]) - (t.width/2);
        lt += 17;
        $('cat_desc_' + cat_id).style.top = tp + 'px';
        //$('cat_desc_' + cat_id).style.left = lt + 'px';
        $('cat_desc_' + cat_id).style.display = "";
        positioned_cat[positioned_cat.length] = cat_id;
    } else {
        $('cat_desc_' + cat_id).style.display = "";
    }
}

function hide_cat_description(cat_id,a_tag) {
    $('cat_desc_' + cat_id).style.display = "none";
}


var positioned_cat_up = Array();

function show_cat_comment_up(cat_id,a_tag) {
    if(!in_arrays(cat_id,positioned_cat_up)) {
        var t = Element.getDimensions('cat_comment_up_' + cat_id)
        $('cat_comment_up_' + cat_id).clonePosition(a_tag,{setWidth: false, setHeight: false});
        $('cat_comment_up_' + cat_id).style.height = t.height;
        $('cat_comment_up_' + cat_id).style.width = t.width
        ary = $('cat_comment_up_' + cat_id).style.top.split('px');    
        //var tp = parseInt(ary[0]) - t.height;
        var tp = parseInt(ary[0]);
        if(navigator.appName == "Microsoft Internet Explorer") {tp += 30;}
        else{ tp +=0;}
        ary2 = $('cat_comment_up_' + cat_id).style.left.split('px');            
        var lt = parseInt(ary2[0]) - (t.width/2);
        //var lt = parseInt(ary2[0]);
        lt += 20;
        $('cat_comment_up_' + cat_id).style.top = tp + 'px';
        $('cat_comment_up_' + cat_id).style.left = lt + 'px';
        $('cat_comment_up_' + cat_id).style.display = "";
        positioned_cat_up[positioned_cat_up.length] = cat_id;
    } else {
        $('cat_comment_up_' + cat_id).style.display = "";
    }
}

function hide_cat_comment_up(cat_id,a_tag) {
    $('cat_comment_up_' + cat_id).style.display = "none";
}


var positioned_cat_down = Array();

function show_cat_comment_down(cat_id,a_tag) {
    if(!in_arrays(cat_id,positioned_cat_down)) {
        var t = Element.getDimensions('cat_comment_down_' + cat_id)
        $('cat_comment_down_' + cat_id).clonePosition(a_tag,{setWidth: false, setHeight: false});
        $('cat_comment_down_' + cat_id).style.height = t.height;
        $('cat_comment_down_' + cat_id).style.width = t.width
        ary = $('cat_comment_down_' + cat_id).style.top.split('px');    
        //var tp = parseInt(ary[0]) - t.height;
        var tp = parseInt(ary[0]);
        if(navigator.appName == "Microsoft Internet Explorer") {tp += 30;}
        else{ tp +=0;}       
        ary2 = $('cat_comment_down_' + cat_id).style.left.split('px');    
        var lt = parseInt(ary2[0]) - (t.width/2);
        //var lt = parseInt(ary2[0]);
        lt += 20;
        $('cat_comment_down_' + cat_id).style.top = tp + 'px';
        $('cat_comment_down_' + cat_id).style.left = lt + 'px';
        $('cat_comment_down_' + cat_id).style.display = "";
        positioned_cat_down[positioned_cat_down.length] = cat_id;
    } else {
        $('cat_comment_down_' + cat_id).style.display = "";
    }
}

function hide_cat_comment_down(cat_id,a_tag) {
    $('cat_comment_down_' + cat_id).style.display = "none";
}

function hide_instructions(userID) {
    var url = 'http://w4.cloudspace.com/libertyfirst/ajax/hide_instructions.php';
    var pars = 'user_id=' + userID
    var myAjax = new Ajax.Request(url, 
    	{
    		method: 'get', 
    			parameters: pars, 
    			onComplete: showResponse
    	});
}
    
    	
function showResponse(originalRequest)
{
	//put returned XML in the textarea
   // alert('done ' + originalRequest.responseText);
	//$('result').value = originalRequest.responseText;
}
 
  
function countdown()
{
	var countdown = $('countdown');
        var count = countdown.innerHTML;
		count--;
        countdown.innerHTML=count;
        if(count > 0){setTimeout('countdown();',1000);}
        else{window.location="edit-profile.php";}

}
