var box = {};

window.addEvent('domready',function() {


    SqueezeBox.assign($$('a[rel=submitbox]'), {
		size: {x: 620, y:460},
        ajaxOptions: {
			method: 'get' // we use GET for requesting plain HTML
			},
	   overlayOpacity: 0.8
	});
	
	SqueezeBox.assign($$('a[rel=editbox]'), {
		size: {x: 620, y:460},
        ajaxOptions: {
			method: 'get' // we use GET for requesting plain HTML
			},
	   overlayOpacity: 0.8
	});

    SqueezeBox.assign($$('a[rel=contactbox]'), {
		size: {x: 550, y:350},
        ajaxOptions: {
			method: 'get' // we use GET for requesting plain HTML
			},
	   overlayOpacity: 0.8
	});
	
	 SqueezeBox.assign($$('a[rel=adsbox]'), {
		size: {x: 590, y:150},
        ajaxOptions: {
			method: 'get' // we use GET for requesting plain HTML
			},
	   overlayOpacity: 0.8
	});
	
	SqueezeBox.assign($$('a[rel=aboutbox]'), {
		size: {x: 550, y:480},
        ajaxOptions: {
			method: 'get' // we use GET for requesting plain HTML
			},
	   overlayOpacity: 0.8
	});

    
  
	//opacity / display fix
	
	$$('#avatars-area .avatar-info').setStyles({
		opacity: 0,
		display: 'block'	
	});
	
	//put the effect in place
	
	//$$('#avatars-area li').each(function(el,i) {
	$$('#avatars-area td').each(function(el,i) {
		el.addEvents({
			'mouseenter': function() {
			    var obj = el.getElement('div');
			    if(!obj) return;
				obj.set('tween', { duration: 10 }).fade('in');
				obj.setStyle('left',el.getPosition('main-info').x);
				obj.setStyle('top',el.getPosition('main-info').y+80);
			},
			'mouseleave': function() {
			    var obj = el.getElement('div');
			    if(!obj) return;
				obj.fade('out');
			}
		});
	});

    var detectBrokenAvatarsID = detectBrokenAvatars.periodical(20*1000);
	
});

function fieldEdit(e){
 /*var intKeyCode = 0;
if (navigator.appName == "Microsoft Internet Explorer")
{
if (window.event.keyCode == 13)
{
alert('eee');
}
}
if (navigator.appName == "Netscape")
{
//alert(e.which);
intKeyCode = e.which;
if (intKeyCode == 13)
{
alert('eee');
}
}*/
}

function closeBox(){
  SqueezeBox.close();
}

function detectBrokenAvatars(){
  var images = $$('#avatars-area td img');
  if(images)
    images.each(function(el){
     if(el.getSize().y < 40){
      el.set('src', 'images/noavatar.gif');
      var elId = el.get('id').split('_')[1];
      if(elId)
      var req = new Request.HTML({
            method: 'post',
            data:{id:elId},
            url: 'clean.php'
            //update: $('sbox-content'),
            //async:false

       }).send();
       
     }
    });
  
}

function limitText(limitField, limitCount, limitNum) {
	if (limitField && limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
	    var limc = $(limitCount);
	    if(limc)
		  limc.set('html',limitNum - limitField.value.length);
	}
}


function getVerification(){
     var req = new Request.HTML({
            method: 'post',
            url: 'submit.php?btnVerify=1',
            update: $('sbox-content'),
            async:false

       }).post($('avVerify'));
}

function getSendPasswordFrom(){
var req = new Request.HTML({
            method: 'get',
            url: 'submit.php?btnVerify=1',
            update: $('sbox-content'),
            async:false

       }).get();
}

function getLoginForm(){
var req = new Request.HTML({
            method: 'get',
            url: 'login.php',
            update: $('sbox-content'),
            async:false

       }).get();
}

function requestEdit(){

   var redit = new Request.HTML({
            method: 'post',
            url: 'submit.php?btnEdit=1',
            update: $('sbox-content')

       }).post($('avEdit'));
}

function requestConfirm(){

   var redit = new Request.HTML({
            method: 'post',
            url: 'submit.php?btnConfirm=1',
            update: $('sbox-content')

       }).post($('avEdit'));
}

function requestDelete(){

   var redit = new Request.HTML({
            method: 'post',
            url: 'submit.php?btnDel=1',
            update: $('sbox-content')

       }).post($('avEdit'));
}

function submitAvatar(){
     var req = new Request.HTML({
            method: 'post',
            url: 'submit.php?btnSubmit=1',
            update: $('sbox-content')
       }).post($('avForm'));
}

function submitContact(){
     var req = new Request.HTML({
            method: 'post',
            url: 'contact.php?btnSubmitContact=1',
            update: $('sbox-content')
       }).post($('contactForm'));
}

function submitLogin(){     
     var req = new Request.HTML({
            method: 'post',
            url:'submit.php?btnLogin=1',
            update: $('sbox-content')
       }).post($('loginForm'));
}


