// SELEX WEB
// by Totbits Solutions (www.totbits.com)
//
// Get out of my code Mr. Parkman!

var Site = { 
	//Parametros a configurar
	kwick_param : {
		EXPANDED_WIDTH: 200,
		TRANSITION_DURATION: 200
	},
	init: function() {
		if ($('#kwicks').length) Site._init_kwicks();
		if ($('#photo_intro').length) Site._init_intro();
		if ($("#gamas_slider").length) $("#gamas_slider").codaSlider();
		if (document.all) {
			$("#menu li").hoverClass ("sfhover");
		}
	},
	initSelectBox: function() {
		if (!document.all) return;
		$('a.select_box').hover(
			function() { $(this).find('td.text').addClass('sel'); },
			function() { $(this).find('td.text').removeClass('sel'); }
		).find('table').css('cursor', 'pointer').bind('click', function() {
			window.open(this.parentNode.href, '_self');
		});
	},
	initSearchBox: function() {
		$("#cat").bind('change', Site._search_gama_change);
		Site._search_gama_change();
	},
	_search_gama_change: function() {
		var t = $("#cat");
		if (t.val()==9) {
			$("#tr_gama").hide();
			$('#gama').attr("disabled","1");
		} else {
			$("#tr_gama").show();
			$('#gama').attr("disabled","");
		}		
	},
	_init_kwicks : function() {
	  Site.kwick_param.TOTAL_WIDTH = $('#kwicks').width();
	 
		var kwicks = $('a.kwick');
		Site.kwick_param.TOTAL_WIDTH = $('#kwicks').width();
		Site.kwick_param.ORIGINAL_WIDTH = kwicks.width();
		var separation = Site.kwick_param.TOTAL_WIDTH - Site.kwick_param.ORIGINAL_WIDTH*kwicks.length;
		Site.kwick_param.SMALL_WIDTH = (Site.kwick_param.TOTAL_WIDTH-Site.kwick_param.EXPANDED_WIDTH - separation)/(kwicks.length-1);
		
		kwicks.bind('mouseover', function() {
			var t = this;
			$(t).stop().animate({ width: Site.kwick_param.EXPANDED_WIDTH+'px' }, Site.kwick_param.TRANSITION_DURATION);
			kwicks.each(function(i) { 
				if (this!=t) $(this).stop().animate({ width: Site.kwick_param.SMALL_WIDTH+'px' }, Site.kwick_param.TRANSITION_DURATION);
			});
		}).bind('mouseout', function() {
			kwicks.stop().animate({ width: Site.kwick_param.ORIGINAL_WIDTH+'px' }, Site.kwick_param.TRANSITION_DURATION);
		});
	},
	_init_intro : function() {
		var _intro_background = $('#text_intro_bg');
		$('#menu li.main').hover(
			function() {
				$('#photo_intro div.text_intro').hide();
				var rel,text_intro;
				if ((rel = this.getAttribute('rel')) && (text_intro = $('#intro_'+rel))) {
					text_intro.animate({ height: '72px' }, 200);
					_intro_background.stop().css('height', '1px').animate({ height: '72px' }, 200);
				}
			},			
			function() {
				var rel,text_intro;
				if ((rel = this.getAttribute('rel')) && (text_intro = $('#intro_'+rel)))
					text_intro.stop().animate({ height: '1px' }, 200);
					_intro_background.stop().animate({ height: '1px' }, 200);
			}
		);
	}
};

$.fn.hoverClass = function(c) {
	return this.each(function(){
		$(this).hover( 
			function() { $(this).addClass(c);  },
			function() { $(this).removeClass(c); }
		);
	});
};	

$(Site.init);
