/* set global variable for boxy window */
var contactBoxy = null;

var timeout = 1000;
var closetimer = 0;
var ddmenuitem = 0;

function jsddm_close(){
    if (ddmenuitem) $("#"+ddmenuitem).slideUp();
}

function jsddm_timer(){
  	closetimer = window.setTimeout(jsddm_close, timeout);
}

function jsddm_canceltimer(){
    if (closetimer) {
        window.clearTimeout(closetimer);
        closetimer = null;
    }
}


function init(){
	
	if ($('.corner').length > 0){
		$('.corner').corner("round 8px #e1e1e1");
	}
	
	//Check browser version
	if($.browser.msie && $.browser.version=="6.0") {
		
		//Function menu effects
		$('li.headlink').hover(
			function() {
				$('ol', this).css('display', 'block'); 
			},
			function() { 
				$('ol', this).css('display', 'none'); 
			}
		);
		
		
		
	}else{
		
		$('li.headlink').hover(
		//open
		function(e){
			jsddm_canceltimer();
			
			if (ddmenuitem != $('ol', this).attr('id')) jsddm_close();
			
			var position = $(this).position();
			ddmenuitem = $('ol', this).attr('id'); 
			$("#"+ddmenuitem).slideDown(300).css('z-index',9999);
			
		},
		//close
		function(e){
			jsddm_timer();
		});
		
	}
		
	//boxy - Facebook Light Dialog Box
	$('.exclude').unbind();
	$('.exclude').bind("click", function() {
		_url 	= $(this).attr('url');
		_data = $(this).attr('target_id');
		_hide = $(this).attr('hide');
		_msg 	= $(this).attr('msg');
		 		
		Boxy.confirm(
			_msg,  
				function() {
					//case true 
					//alert('Confirmed!');
					$.post(_url, 
						   { 'id' : _data }, 
						   _callback_Exclude(_data, _hide), 
						   "json");
				}, 
				{
					//Box's Title
					title: 'Message'}
				);
		return false;
  	});
	
	$('.answer').unbind();
	$('.answer').bind("click",function() {
        var boxy_content;
		_from_person = $(this).attr('from_person');
		_to_person = $(this).attr('to_person');
		_parent = $(this).attr('parent');
		_url = $(this).attr('url');
		
        contactBoxy = Boxy.load("/profile/boxy/" , 
				{ 	 
				title: "Comentar mensagem",
				draggable: false,
				modal: true,
				closeText:'[Fechar]',
				 
				behaviours: function(c) {
	                c.find('#feedback').submit(function() {

					    Boxy.get(this).setContent("<div style=\"width: 300px; height: 150px\">Sending...</div>");
	                    
	                    $.post(_url, { message: c.find("#message").val() , to_person: _to_person, parent: _parent, from_person: _from_person },
							function(data){
		                        /*set boxy content to data from ajax call back*/
		                        //Boxy.get(this).setContent("<div style=\"width: 300px; height: 150px\">"+data+"</div>");
								//contactBoxy.setContent("<div style=\"width: 300px; height: 150px\">"+data+"</div>");
								$('.boxy-content').html(data.msg_return);
								//Jquery add new li on last list
								
								if ( $('li#line_' + _parent + ' ul li:last').hasClass('color') ) {
									$('li#line_' + _parent + ' ul li:last').after(data.new_line);
								}else{
									$('li#line_' + _parent + ' ul li:last').after(data.new_line);
									$('li#line_' + _parent + ' ul li:last').addClass('color')
								}
								//contactBoxy.hide();
								
		                    }, "json"
						);
	                    return false;
					});
				}
			}
			); 
	});
	
	$('#logo_link_home').click(function(){
		window.location = '/';
	});
	
	
	if ($('.slide').length == 1){
		$('#slide-controls').hide();
	}
	
	/*
	if ( $('.fixPNG').length() ) {
		
		DD_belatedPNG.fix('.pngFIX'); 
		DD_belatedPNG.fix('.slide'); 
		
	}*/
	
	
}


function _callback_Exclude(_data, _hide){
	if (_hide){
		$('.line_' + _hide).fadeOut();
	}else{
		$('.line_' + _data).fadeOut();
	}
}


function esqueciMinhaSenha(){
        var createpass = $('#createpass').val();

        if (createpass == 1){
                $('#createpass').val(0);
        }else{
                $('#createpass').val(1);
        }
		
        $('#esqueciMinhaSenha').slideToggle();
}



$(document).ready(init);


 
