/*
JS SyFy based Gallery
@author: Bruno Azisaka Maciel
*/

var SyFy = {
  
  maxImgWidth: 300,
  minImgWidth: 150,
  maxImgHeight: 150,
  minImgHeight: 75,
  maxSlotWidth: 300,
  minSlotWidth: 150,
  maxSlotHeight: 170,
  minSlotHeight: 75,
  slotMargin: 0,
  
  init: function() {
	
    $('ul.syfy').css({ height: (SyFy.maxSlotHeight + ((SyFy.minSlotHeight + SyFy.slotMargin) * 4)) + 'px', overflow: 'hidden', display: 'block', width: SyFy.maxSlotWidth + 'px' });
    $('ul.syfy li img').css({ width: SyFy.minImgWidth, height: SyFy.minImgHeight });
    
	$('#thumb0').addClass('show');

    $('ul.syfy li').each(function() {
		$(this).children('div, a').hide();
		$(this).children('div').css({ clear: 'both' }).addClass('description');
		$(this).children('a').addClass('quick').show();
		$(this).css({ width: SyFy.maxSlotWidth + 'px', height: SyFy.minSlotHeight + 'px', 'margin-bottom': SyFy.slotMargin + 'px' }).addClass('tab');
    });

    $('ul.syfy li.tab').live('mouseover', function() { SyFy.rollOver(this) });
    
    SyFy.activeSlot($('ul.syfy li').eq(0));

  },
  
  rollOver: function(element) {
	$('.featured').remove();
	$('.play').remove();
    $('ul.syfy li.active').queue(function() {
	
		$('.thumb a').remove();
	
      	$(this).children('div').hide();
		$(this).children('img').animate({ width: SyFy.minImgWidth, height: SyFy.minImgHeight }, 200);
   
		if(!document.getElementById('interna')) {
			$('div.thumb').removeClass('show');
			var el = document.getElementById('thumb' + element.id);
			el.className += ' show';
		}
		
		$(this).unbind('click');
		SyFy.activeSlot(element);
   
		$(this).children('a').show();
		$(this).removeClass('active').addClass('tab').css({ height: SyFy.minSlotHeight + 'px', cursor: 'default' });
		$(element).children('.description').children('h3').css('background', 'none');
    });
    
  },
  
  activeSlot: function(element) {
    $(element).children('a').hide();
    $(element).children('img').animate({ width: SyFy.maxImgWidth, height: SyFy.maxImgHeight }, { duration: 350, complete: function() {
        
        if($('#simple').length == 1){
			return;
		}

		// destaque na imagem pequena ativa
      	var featured = document.createElement('div');
		$(featured).addClass('featured').hide();
		$(element).append(featured);
		($.support.scriptEval ? $(featured).fadeIn(500) : $(featured).show());
		$(element).children('.description').children('h3').css('background', 'red');
		
		// player imagem grande
		//if ($('#thumb' + $(element).attr('id') + ":has(object)").length == 0){
		//	var play = document.createElement('div');
		//	$(play).addClass('play').hide();
		//	$('#thumb' + $(element).attr('id')).append(play);
		//	($.support.scriptEval ? $(play).fadeIn(500) : $(play).show());
		//}
				
		// link imagem grande
		if ($('#thumb' + $(element).attr('id') + ":has(object)").length == 0){
			var play_link = document.createElement('a');
			$(play_link).attr('href', $(element).children('a').attr('href'));
			$('#thumb' + $(element).attr('id')).append(play_link);
			($.support.scriptEval ? $(play_link).fadeIn(500) : $(play_link).show());
		}
    } });

    $(element).removeClass('tab').addClass('active');
	
    $(element).css({ height: SyFy.maxSlotHeight + 'px', cursor: 'pointer' });
    $(element).bind('click', function() {
		window.location = $(element).children('a').attr('href');
	});
    $(element).children('div').fadeIn();

	$(element).addClass($(element).children('a').attr('href').split("/")[2]);
	
	if($(element).children('a').attr('href').split("/")[1] == 'Basico'){
		$(element).addClass($(element).children('a').attr('href').split("/")[1]);
	}
	
	if($(element).children('a').attr('href').split("/")[1] == 'submarino'){
		$(element).addClass($(element).children('a').attr('href').split("/")[3]);
	}
	
    $(element).dequeue();
  }
  
}