 var curProductNum = 0;
 var curNoticiasPage = 0;
 var maxNoticiasPage = 0;
 
 var solucionesOpen = false;
 var curSolucion = 0;
 
 var $j = jQuery.noConflict();

 $j(document).ready(function($j){

	$j('#page_home #content a').each(function(i,o){
		addFadeEffect(o);
	});
	$j('#page_section #content a').each(function(i,o){
		addFadeEffect(o);
	});
	$j('#page_soluciones-home #content a').each(function(i,o){
		addFadeEffect(o);
	});
	
	$j('#page_productdetail #content a').each(function(i,o){
		addFadeEffect(o);
	});
	
	productScroll();
	
	
	$j('.outerBox').autoscroll(AUTOSCROLL_Y);
	
	
	
	$j('#menu li').each(function(i,o){
		$j(o).css({'opacity':0,'background-color':'#000'});
		$j(o).bind('mouseenter',function(e){
			$j(o).stop();
			$j(o).animate({'opacity': 0.5})
		});
		$j(o).bind('mouseleave',function(e){
			$j(o).stop();
			if(!$j(o).hasClass('active')){
				$j(o).animate({'opacity': 0})
			}
		});
	});
	$j('#menu li.active').css({opacity:0.5});
	

	
	$j('.accContent img').each(function(i,o){
		if($j(o).attr("alignment")=="left"){
			$j(o).css({float:'left'});
		}
		if($j(o).attr("alignment")=="right"){
			$j(o).css({float:'right'});
		}
	});
	
	$j('#introSlideshow').cycle();
	
	$j('#noticiasBox').show();
	
	$j('#noticiasHolder').accordion({
		header: '.noticiaTitle',
		autoheight: false,
		active: false,
		fillSpace: false,
		alwaysOpen: false
	});
	
	$j('#contactBox a.contactLink').each(function(i,o){
		$j(o).css({'opacity':0,'background-color':'#000'});
		$j(o).bind('mouseenter',function(e){
			$j(o).stop();
			$j(o).animate({'opacity': 0.5})
		});
		$j(o).bind('mouseleave',function(e){
			$j(o).stop();
			if(!$j(o).hasClass('active')){
				$j(o).animate({'opacity': 0})
			}
		});
	});
	
	$j('#solucionesMenu a').each(function(i,o){
		$j(o).css({'opacity':1,'background-color':'#000'});
		$j(o).bind('mouseenter',function(e){
			$j(o).stop();
			$j(o).animate({'opacity': 0.5})
		});
		$j(o).bind('mouseleave',function(e){
			$j(o).stop();
			if(!$j(o).hasClass('active')){
				$j(o).animate({'opacity': 1})
			}
		});
		$j(o).click(function(e){
			e.preventDefault();
			if(!$j(o).hasClass('active')){
				$j('#solucionesMenu a.active').animate({'opacity': 1});
				$j('#solucionesMenu a.active').removeClass('active');
				$j(o).addClass('active');
				
				
				var curActive = $j('.accMainContent').eq(curSolucion);
				//curActive.animate({opacity:0},"fast",function(){
					curActive.css({display:'none',opacity:0});
					
					$j('.accMainContent').eq(i).css({display:'block'});
					$j('.accMainContent').eq(i).stop();
					$j('.accMainContent').eq(i).animate({opacity:1});
					curSolucion = i;
					if(!solucionesOpen){
						$j('#solucionesContent').animate({opacity:1});
						solucionesOpen = true;
					}
					
				//});
				
			}
		});
	});
	
	$j('.accMainContent').each(function(i,o){
		$j(o).css({opacity:0,display:'none'});
	})
	$j('#solucionesContent').css({opacity:0,visibility:'visible'});
	
	

	$j('.solucionHolder').each(function(i,o){
		var curH = $j(o).children('h2');
		var curC = $j(o).children('.accContent');
		curC.slideUp(0);
		curH.click(function(e){
			e.preventDefault();
			closeSoluciones();
			curC.stop();
			curC.slideToggle("slow");
			$j(o).addClass('opened');
		});
	});
	
	
	
	$j('#cat3turismo').click(function(e){
		e.preventDefault();
		if($j('#productList ul.innerBox li.cat3industrial').length){
			$j('#productList ul.innerBox li.cat3industrial').fadeOut("slow",function(){
				$j('#productList ul.innerBox li.cat3turismo').fadeIn();
			});
		} else {
			$j('#productList ul.innerBox li.cat3turismo').fadeIn();
		}
	});
	$j('#cat3industrial').click(function(e){
		e.preventDefault();
		if($j('#productList ul.innerBox li.cat3turismo').length){
			$j('#productList ul.innerBox li.cat3turismo').fadeOut("slow",function(){
				$j('#productList ul.innerBox li.cat3industrial').fadeIn();
			});
		} else {
			$j('#productList ul.innerBox li.cat3industrial').fadeIn();
		}
	});





	$j('.accContent a').attr({ target: "_blank" });
	
	
 });
 
 
 function closeSoluciones(){
 	$j('.accMainContent').eq(curSolucion).children('.solucionHolder.opened').each(function(i,o){
		$j(o).children('.accContent').slideUp("slow");
		$j(o).removeClass('opened');
	});

 }
 
 
 function enableEl(el){
	$j(el).removeClass('disabled');
	$j(el).css({opacity:1});
 }
 
 function disableEl(el){
	$j(el).addClass('disabled');
	$j(el).css({opacity:0.5});
 }
 
 function loadNoticias(){
 	//alert(curNoticiasPage);
	$j('#noticiasBox').load('getNoticias.php',{'p':curNoticiasPage});
 }
 
 
 
 function addFadeEffect(element){
 	if(!$j(element).hasClass('inactive')){
		$j(element).bind('mouseenter',function(event){
			$j(element).stop().animate({'opacity':0.3});
		});
		$j(element).bind('mouseleave',function(event){
			$j(element).stop().animate({'opacity':1});
		});
	} else {
		$j(element).css({opacity: 0.3});
		$j(element).click(function(e){
			e.preventDefault();
		});
		$j(element).bind('mouseenter',function(event){
			event.preventDefault();
			$j('#productMessage').fadeIn("slow");
		});
	}
 };
 
 function productScroll(){
	$j("#productList a").each(function(i,o){
		$j(o).click(function(event){
			event.preventDefault();
			if(!$j(o).hasClass('active')){
				$j("#productList a.active").removeClass('active');
				$j(o).addClass('active');
			}
			moveProductScroll(i);
			curProductNum=i;
		});
	});
	
	$j("#arrowUpProdDetail").click(function(){
		if(curProductNum>0){
			curProductNum--;
		}
		moveProductScroll(curProductNum);
	});
	
	$j("#arrowDownProdDetail").click(function(){
		if(curProductNum<$j("#productList a").size()-1){
			curProductNum++;
		}
		moveProductScroll(curProductNum);
	});
	
	if($j('#openProdNumber').length){
		curProductNum = $j('.productDetail').index($j("#product-"+$j('#openProdNumber').html()));
		moveProductScroll(curProductNum);
	}
	
 }
 
 
 
 function moveProductScroll(pos){
 	$j("#productDetailList").animate({'top': pos*(-411)});
	
	$j("#productList a.active").removeClass('active');
	$j("#productList a").eq(pos).addClass('active');
 }

