
var dropDownHeight = 0;

$(document).ready(function(){
	$('#blockSearch').each(function(){
		var selectEl = $(this).find('select[name=platform]');
		var blockDropDownEl = $(this).find('div.blockDropDown');
		selectEl.css('display','none').attr('disabled','disabled');
		blockDropDownEl.css('display','block');
		blockDropDownEl.find('#selector').hover(
			function(){ DD_timerOpen('div.blockDropDown') ;},
			function(){ DD_timerClose('div.blockDropDown') ;}
			//function(){}
			);
		blockDropDownEl.find('#dropdown').hover(
			function(){ DD_timerOpen('div.blockDropDown') ;},
			function(){ DD_timerClose('div.blockDropDown') ;}
			//function(){}
			);

		// FIX IE 6 SELECT Z-INDEX
		blockDropDownEl.find('#dropdown').bgiframe();

		dropDownHeight = blockDropDownEl.find('#dropdown').height();

		blockDropDownEl.find('#dropdown li a').each(function(){
			var linkEl = $(this);
			linkEl.unbind('click').click(function(){
				blockDropDownEl.find('#dropdown li a').removeClass('activ');
				linkEl.addClass('activ');
				linkEl.find('input[type=radio]').attr('checked','checked');
				$('div.blockDropDown #selector span:first').html(linkEl.attr('title'));
				//return false;
				});
			});
	});
});

var inTimeout    = 100;
var outTimeout    = 400;
var blockDropDown = 0;

function DD_open(element){
	//alert('activate');
	DD_cancelTimer(element);
	if(!$(element).find('#selector').hasClass('activ')){
		$(element).find('#selector, #dropdown').addClass('activ');
		if($(element).find('#dropdown').css('height') != dropDownHeight+'px' && $(element).find('#dropdown').css('height') != 'auto'){
			$(element).find('#dropdown').stop().animate({
				height: dropDownHeight
			},250);
		}else{
			$(element).find('#dropdown').stop().slideDown(250);
		}
	}else{
		$(element).find('#selector, #dropdown').addClass('activ');
		if($(element).find('#dropdown').css('height') != 'auto'){
			$(element).find('#dropdown').stop().animate({
				height: dropDownHeight
			},100);
		}
	}
}

function DD_close(element) {
	//alert('desactivate');
	DD_cancelTimer(element);
	if($(element).find('#dropdown').hasClass('activ')){									
		$(element).find('#dropdown').stop().animate({
			height: '0px'
		},450,function(){
			$(element).find('#dropdown').css({display: 'none'});
			$(element).find('#dropdown').removeClass('activ');
			$(element).find('#selector').removeClass('activ');
		});
	}
}

function DD_timerOpen(element) {
	DD_cancelTimer(element);
	$(element).unbind('click').click(function(){
		DD_open(element);
		return false;
	});
	window.setTimeout("$('"+element+"').trigger('click')", inTimeout);
}

function DD_timerClose(element) {
	DD_cancelTimer(element);									
	$(element).unbind('click').click(function(){
		DD_close(element);
		return false;
	});
	window.setTimeout("$('"+element+"').trigger('click')", outTimeout);
}

function DD_cancelTimer(element) {
	$(element).unbind('click');
}
