// JavaScript Document

function createCaption(OBJ){
		$(OBJ).css('z-index','0');
		var txt		 = $(OBJ).attr('alt');
		var width 	 = $(OBJ).width();
		var orgHeight = $(OBJ).height;
		var height 	 = Math.round($(OBJ).height / 5);
		width 		 -= 10; // take out padding/
		
		//alert(width +' > '+ $(OBJ).attr('width') );
		var container_style = {
							'width':width
					};
		var cap = $('<div class="caption"><div/>');
		cap.css(container_style);
		cap.html(txt);
		return cap;
}


function stylizeAlt(){
	$('.stylize-Alt').each(function(){
								
				var img = $(this);
				img.css('z-index','0');
				var txt		 = img.attr('alt') || img.attr('title');
				var width 	 = img.width();
				var orgHeight = img.height();
				var height 	 = Math.round(img.height() / 5);
				width 		 -= 10;
				var classes = "";
				if(img.hasClass('alignright')){ img.removeClass('alignright'); classes+= "alignright "; }
				if(img.hasClass('alignleft')){ img.removeClass('alignleft'); classes+= "alignleft "; }
				
				//var classes = $(this).attr('class');
				var d = $('<div class="img_alt '+classes+'"></div>');
				//d.addClass(classes);
				$(this).wrap(d);
				
				var container = $('<div />');
				var _css = {
							'width':width, 'height':0, 'z-index':9999, 'opacity':'0',
							'color':'#fff', 'background-color':'#685D11',
							'position':'absolute', 'bottom':0, 'left':0, 'visibility':'visible',
							'text-align':'center', 'font-family':'Arial', 'font-size':'12px', 'padding':'5px',
							'overflow':'hidden', 'background-position':'bottom', 'background-repeat':'repeat-x'
							};
				container.css(_css).html(txt);
				$(this).parent().append(container);
		
				var hoverObj = $('<img class="spacer" src="'+spacer+'" />');
					hoverObj.height( $(this).height() );
					hoverObj.width( $(this).width() );
				$(this).parent().append(hoverObj);
		
				$(hoverObj).hover(function(){
						$(container).stop().animate({ 
								height: height+"px", 
								opacity: 0.7
							}, 500 );
									   
					},function(){
						$(container).stop().animate({ 
								height: "0px", 
								opacity: 0.0
							}, 500 );
						
				});
										
	});
}


function initBody(){
	// set top menu/
		$("#topmenu ul li a").html("");
		$("#topmenu").show();
	

	// Set color box/
		//var opt = {transition:'elastic', scrolling:'false', preloading:'false', iframe:true, width:"760", height:"600"};
		var opt = {transition:'elastic', scrolling:'false', preloading:'false'};
		$("a[rel='ColorBoxModel']").colorbox(opt);
		//$('.gallery').find('a').colorbox(opt);
		$('.gallery').each(function(){
			$(this).find('a').attr("rel","[rel='ColorBoxModel']").colorbox(opt);
			//$(this).find('a').colorbox(opt);
		});
		
		// fixing nexGenPlugin
		$('.gallery_item').colorbox(opt);


	// stylize image alt/
		stylizeAlt();
}


$(document).ready(function() {
	if ($.browser.msie && $.browser.version.substr(0,1)<8) {
		$('#listado_productos ul li').hover(function() {
			$(this).addClass('li-hover');
		}, function() {
			$(this).removeClass('li-hover');
		});
	}
});


