Event.observe(window,'load',resizeList);

function resizeList()
{
	if($('desafios'))
	{
		var height = $('desafios').getHeight();
		if(height > 225)
			$('desafios').style.height = '225px';
	}
}


/* generic slider navigation with N items */
function resizeSlider(slider_id, item_width)
{
	var height = $(slider_id).childElements().length * item_width;
	$(slider_id).style.height = height + 'px';
	$(slider_id).style.top = '0px';
}

function goUp(slider_id, item_width)
{
	var width = $(slider_id).style.top;
	width = width.substring(0, width.length-2);
	
	item_width = parseInt(item_width);
	
	if(width < 0 && width < item_width && width%item_width!=0)
	{
		var navigate = parseInt(width)+item_width;
		new Effect.Move(slider_id, {
		  y: -navigate, x: 0, mode: 'relative'
		});
	}
	else if(width < 0 && width >= -item_width)
	{
		
		new Effect.Move(slider_id, {
		  y: item_width, x: 0, mode: 'relative'
		});
		
	}
	else if(width < 0)
	{
		
		new Effect.Move(slider_id, {
		  y: item_width, x: 0, mode: 'relative'
		});	
	}
}


function goDown(slider_id, item_width)
{
	var width = $(slider_id).style.top;
	width = width.substring(0, width.length-2);
	
	total_items = $(slider_id).childElements().length;
	var tempWidth = 3 * item_width - total_items * item_width;
	
	item_width = parseInt(item_width);
	
	if(width > tempWidth && width < item_width && width%item_width!=0)
	{
		var navigate = parseInt(width)+item_width;
		new Effect.Move(slider_id, {
		  y: -navigate, x: 0, mode: 'relative'
		});
	}
	else if(width > tempWidth && width <= -item_width)
	{
		new Effect.Move(slider_id, {
		  y: -item_width, x: 0, mode: 'relative'
		});
	}
	else if(width > tempWidth)
	{
		new Effect.Move(slider_id, {
		  y: -item_width, x: 0, mode: 'relative'
		});	
	}
}


function changeReport(activate)
{
	totalReports = $('slider').childElements().length;
	
	for(i = 1; i <= totalReports; i++)
	{
		if(i == activate)
		{
			$('list'+i).addClassName('active');
			new Effect.Appear('report'+i, { duration: 2.0 });
		}
		else
		{
			$('list'+i).removeClassName('active');
			new Effect.Fade('report'+i, { duration: 2.0 });
		}
		
		
	}
	
}


function rateImgLighbox(rating,chaaid){

    url = '/desafio/?rating='+rating+'&chaid='+chaaid+'';
    new Ajax.Request(url,{
            method: 'get',
            onComplete: function(transport) {
                
                            json = transport.responseJSON;
                            
                            if(json.status == 1) {
                                  rating = rating * 10;
                                  $('current_rating').style.width = rating+'px';
                                  $('ratelinks').style.display = 'none';
                            }else{
                            }
            },
            
            onFailure: function(transport) {
                
            }   
        });
    return false;
}


function changeImg(id){
    
    url = '/lightbox/?foto='+id+'&ajax=1';
    title = 'Passatempo+7Up+/+Springfield';
    url_stle='http://www.7up.pt/';
    
    
    new Ajax.Request(url,{
            method: 'get',
            onComplete: function(transport) {
                            json = transport.responseJSON;
                            
                            if(json.status == 1) {
                                
                                 if(json.record_preview !=''){
                                     
                                    $('link_anterirorImg').style.display="block";
                                    $('link_anteriror').style.display="block";
                                     
                                    $('link_anterirorImg').onclick = function() { changeImg(json.record_preview) };
                                    $('link_anteriror').onclick = function() { changeImg(json.record_preview) };
                                    
                                 }else {
                                     
                                     $('link_anterirorImg').style.display="none";
                                     $('link_anteriror').style.display="none";
                                     
                                 }
                                
                                if(json.record_next != ''){
                                    $('link_seguinteImg').style.display="block";
                                    $('link_seguinte').style.display="block";
                                    
                                    $('link_seguinteImg').onclick = function() { changeImg(json.record_next) };
                                    $('link_seguinte').onclick = function() { changeImg(json.record_next) };
                                    
                                } else {
                                    
                                    $('link_seguinteImg').style.display="none";
                                    $('link_seguinte').style.display="none";
                                }
                                
                                /* alert(current_vote.value);
                                $('current_rating_'+json.img).style.width = json.current_vote+'px'; */
                                
                                //alert(id);
                                //$('current_rating').style.width =  json.record_vote+'px';
                                
                                //$('current_rating_'+json.img).style.width = json.record_vote+'px';
                                $('current_rating').style.width = json.record_vote+'px';
                                //$('ratelinks').style.display = 'block';
                                
                                $('record_title').update(json.record_title);
                                $('record_name').update(json.record_name);
                                $('record_img').src= IMG_PATH+json.record_img;
                                //$('record_city').update(json.record_city);
                                
                                //rating vote
                                 $('star_1').onclick = function() { rateImgLighbox(1, id) };
                                 $('star_2').onclick = function() { rateImgLighbox(2, id) };
                                 $('star_3').onclick = function() { rateImgLighbox(3, id) };
                                 $('star_4').onclick = function() { rateImgLighbox(4, id) };
                                 $('star_5').onclick = function() { rateImgLighbox(5, id) };
                                
                                 
                                //Links Partilha
                                $('url_fb').href='http://www.facebook.com/sharer.php?u='+url_stle+'foto/?foto='+json.img+'&t='+title+'';
                                $('url_mp').href='http://www.myspace.com/index.cfm?fuseaction=postto&amp;t='+url_stle+'foto/?foto='+json.img+'&amp;u='+title+'&amp;c=';
                                $('url_tt').href='http://twitter.com/home/?status='+url_stle+'foto/?foto='+json.img+'+'+title+'';
                                $('url_gb').href='http://www.google.com/bookmarks/mark?op=edit&bkmk='+url_stle+'/foto/?foto='+json.img+'&title='+title+'';
                                $('url_dl').href='http://del.icio.us/post?url='+url_stle+'foto/?foto='+json.img+'&title='+title+'';
                                
                            }else{
                               
                            }
            },
            
            onFailure: function(transport) {
                
            }   
        });
return false;
} 


//  In my case I want to load them onload, this is how you do it!
Event.observe(window, 'load', loadAccordions, false);

//	Set up all accordions
function loadAccordions() {
    
   // var bottomAccordion = new accordion('vertical_container');
    
    // Open first one
    //bottomAccordion.activate($$('#vertical_container .accordion_toggle')[0]);
    
}
		
		
		
/* acordeao */
function accordToggle(toShow, total)
{
	for(i = 1; i <= total; i++)
	{
	    
	    if($('accord'+i) != null){
	    
            if(i == toShow && $('accord'+i).style.display != '')
            {
                new Effect.BlindDown('accord'+i, { duration: 0.75 });
                bg = 'bg' + i;
                setTimeout("myAdder(bg)", 0);
            }
            else if(i != toShow && $('accord'+i).style.display == '')
            {
                new Effect.BlindUp('accord'+i, { duration: 0.75 });
                bg2 = 'bg' + i;
                setTimeout("myRemover(bg2)", 750);
            }
        }
	}
}

function myRemover(e)
{
	$(e).removeClassName('active');
}

function myAdder(e)
{
	$(e).addClassName('active');
}

