Alcad = {};

Alcad.Common = {
	initialize: function() {
		Lang = Alcad.Common.Lang();
		$(".conuntryChange").change(function(){
			if($(this).val() == 'UNITED STATES')
			{
				$("#stateSelect").fadeIn();
			}
			else
			{
				$("#stateSelect").fadeOut();
			}
		});
	},
	Lang: function(){
		return {
			more_details: "More details",
			hide_details: "Hide details"
		}
	}
};

/* ******* Carousels ******* */

Alcad.Category = {	
	initialize: function() {
		Alcad.Category.openElements();
	},
	openElements:function(){
		$(".block2CategoryBottomLink").unbind('click').click(function() {
				var btn = $(this);
				$(".zone3Product").toggle('slow',function(){
					if($(this).is(':hidden')){
						btn.text(Lang.more_details);
					}else{
						btn.text(Lang.hide_details);
					}
					
				 });
			return false;
		});
	}
}

Alcad.Catalog = {
	initialize: function(){

		$(".block3ProductCatalogBtnView").click(function(){
						
			var self = $(this);
			if(self.children('a').hasClass('on'))
			{
				$(".block3ProductCatalogVisible").removeClass('block3ProductCatalogVisibleActive');
				$(".block3ProductCatalogHidden").slideUp();
				$(".block3ProductCatalogBtnViewLink").removeClass('on').html('View more');
				
				self.children('a').html('View more');
				self.children('a').removeClass('on');
				self.parent().removeClass('block3ProductCatalogVisibleActive');
				self.parent().next().slideUp(function(){

				});
			}
			else
			{
				$(".block3ProductCatalogVisible").removeClass('block3ProductCatalogVisibleActive');
				$(".block3ProductCatalogHidden").slideUp();
				$(".block3ProductCatalogBtnViewLink").removeClass('on').html('View more');
				
				self.children('a').html('Hide details');
				self.children('a').addClass('on');
				self.parent().addClass('block3ProductCatalogVisibleActive');
				self.parent().next().slideDown(function(){

				});
			}
			
			return false;
			
		});

		/*$(".block3ProductCatalogBtnView").toggle(function(){
			$(".block3ProductCatalogVisible").removeClass('block3ProductCatalogVisibleActive');
			$(".block3ProductCatalogBtnViewLink").removeClass('on');
			$(".block3ProductCatalogBtnViewLink").html('View more');
			
			var thisDom = $(this);			
			$(".block3ProductCatalogHidden").slideUp(function(){
				thisDom.html('View more');
				thisDom.removeClass('on');
			});
			
			thisDom.html('Hide details');
			thisDom.addClass('on');
			thisDom.parent().parent().addClass('block3ProductCatalogVisibleActive');
			thisDom.parent().parent().next().slideDown(function(){
				
			});
			
			return false;
			
		}, function(){
			var thisDom = $(this);
			
			
			$(".block3ProductCatalogHidden").slideUp(function(){
				thisDom.html('View more');
				thisDom.removeClass('on');
				thisDom.parent().parent().removeClass('block3ProductCatalogVisibleActive');
			});
			
			return false;
		});*/
		
		$(".block3ProductCatalogHiddenLink2").toggle(function(){
			var thisDom = $(this);
			
			$(".block3ProductCatalogHiddenDiv2").slideUp(function(){
				$(".block3ProductCatalogHiddenLink1").removeClass('block3ProductCatalogHiddenLink1Active');
			});
			
			thisDom.parent().children('.block3ProductCatalogHiddenLink1').addClass('block3ProductCatalogHiddenLink1Active');
			thisDom.parent().next().slideDown();
			
			return false;
			
		},
		function(){
			var thisDom = $(this);
			
			$(".block3ProductCatalogHiddenDiv2").slideUp(function(){
				thisDom.parent().children('.block3ProductCatalogHiddenLink1').removeClass('block3ProductCatalogHiddenLink1Active');
			});
			return false;
			
		});
	}
	
}

Alcad.Downloadcenter = {
	type_key: '',
	category_node_id: '',
	initialize: function(){

		$(".showhideAdvancedResearch").toggle(function(){
			$(".block4DocResearch").slideUp();
			return false;
		},function(){
			$(".block4DocResearch").slideDown();
			return false;
		});
		
		
	},
	setOffset: function(offset){
		$("#block2DocResearchForm input[name=offset]").val(offset);
		$("#block2DocResearchForm").submit();
    
		return false;
	},
	setTypeKey: function(type_key){
		Alcad.Downloadcenter.type_key = type_key;
		$('#ajaxProductSelect').load('/layout/set/ajax/ajax/docsearch_types/'+Alcad.Downloadcenter.type_key+'/'+Alcad.Downloadcenter.category_node_id);
	},
	setCategory: function(node_id){
		Alcad.Downloadcenter.category_node_id = node_id;
		$('#ajaxProductSelect').load('/layout/set/ajax/ajax/docsearch_types/'+Alcad.Downloadcenter.type_key+'/'+Alcad.Downloadcenter.category_node_id);
	}
	
}

Alcad.Carousel = {	
	initialize: function() {
		
		
		$('.block4Content').jcarousel({
			initCallback: mycarousel_initCallback,
			buttonNextHTML: null,
			buttonPrevHTML: null,
			wrap: 'circular',
			animation: 'slow',
			scroll: 1
		});
		
		$('.block2IndexItems').cycle({ 
		    fx:     'fade', 
		    prev:   '.block2MenuLiPrevious', 
		    next:   '.block2MenuLiNext',
		    cleartype:  true,
		    pager:  '#nav',
		    opacity: 0,
		    pagerAnchorBuilder: function(idx, slide) { 
				return '<li class="block2MenuLiBtn marginRight5px" ><a href="#">' + (idx + 1) + '</a></li>';
		    },
			timeout: 0 
		});	
		
		$('.block2NewsItems').cycle({ 
		    fx:     'fade', 
		    speed:  1,
		    prev:   '.block2NewsBtnLeft', 
		    next:   '.block2NewsBtnRight',
		    opacity:0,
		    cleartype:  true,
		    cleartypeNoBg:true,
		    timeout: 0,
		    pagerAnchorBuilder: function(idx, slide) { 
		        // return selector string for existing anchor 
		        return '.block3GenericTopUl .itemColumn:eq(' + idx + ') a'; 
		    },
		    after: function() {  
				
				/*
				var idMain = $('.block2NewsItems .item:visible').attr('id');
				var nbMainId = idMain.split('_');
				
				$('.itemColumn').show();
				$('#itemColumn_'+nbMainId[1]).hide();
				*/
			
	    	} 
		});	
		

		
	}
}

function mycarousel_initCallback(carousel){
	jQuery('.jcarousel-control a').bind('click', function() {
	    carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
	    return false;
	});
    
	jQuery('.jcarousel-scroll select').bind('change', function() {
	    carousel.options.scroll = jQuery.jcarousel.intval(this.options[this.selectedIndex].value);
	    return false;
	});
    
	jQuery('.block4NavRight').bind('click', function() {
	    carousel.next();
	    return false;
	});
    
	jQuery('.block4NavLeft').bind('click', function() {
	    carousel.prev();
	    return false;
	});
}

/* ******* NAVIGATION 2 ******* */
Alcad.Nav2 = {
	initialize: function() {
		OpenSubMenu = Alcad.Nav2.OpenSubMenu();
		$('.blockNav2Link').click(function(){
			return false;
		});
	},
	closeMenu: function(){
		$(".blockNav2SubMenu1").hide();
		$("#btnAboutUs").removeClass("btnAboutUsActive");
		$("#btnServices").removeClass("btnServicesActive");
		$("#btnApplictions").removeClass("btnApplictionsActive");
		$("#btnMarkets").removeClass("btnMarketsActive");
		$("#btnProducts").removeClass("btnProductsActive");
		$("#btnDownloadCenter").removeClass("btnDownloadCenterActive");
	},
	OpenSubMenu: function(){
		/* AboutUs */
		var timeoutAboutus;
		//$("#subMenuAboutUs").hide();
		$("#btnAboutUs").unbind('mouseover').mouseover(function() {
			Alcad.Nav2.closeMenu();
			$("#subMenuAboutUs").show();
			$("#btnAboutUs").addClass("btnAboutUsActive");
			clearTimeout(timeoutAboutus);
		});

		$("#subMenuAboutUs").unbind('mouseover').mouseover(function() {
			$("#btnAboutUs").addClass("btnAboutUsActive");
			$("#subMenuAboutUs").css({'display' : 'block'});
			clearTimeout(timeoutAboutus);
		});
		
		$("#subMenuAboutUs").unbind('mouseout').mouseout(function() {
			timeoutAboutus = setTimeout(function(){
				
				$("#subMenuAboutUs").css({'display' : 'none'});
				$("#btnAboutUs").removeClass("btnAboutUsActive");
				
			}, 1500);
		});
		
		$("#btnAboutUs").unbind('mouseout').mouseout(function() {

				$("#btnAboutUs").removeClass("btnAboutUsActive");
				$("#subMenuAboutUs").hide();

		});

		/* Applications */
		var timeoutApplication;
		//$("#subMenuApplications").hide();
		$("#btnApplictions").unbind('mouseover').mouseover(function() {
			Alcad.Nav2.closeMenu();
			$("#subMenuApplications").show();
			$("#btnApplictions").addClass("btnApplictionsActive");
			clearTimeout(timeoutApplication);
		});

		$("#subMenuApplications").unbind('mouseover').mouseover(function() {
			$("#btnApplictions").addClass("btnApplictionsActive");
			$("#subMenuApplications").css({'display' : 'block'});
			clearTimeout(timeoutApplication);
		});
		
		$("#subMenuApplications").unbind('mouseout').mouseout(function() {
			timeoutApplication = setTimeout(function(){
				$("#subMenuApplications").css({'display' : 'none'});
				$("#btnApplictions").removeClass("btnApplictionsActive");
				
			}, 1500);
		});
		
		$("#btnApplictions").unbind('mouseout').mouseout(function() {

				$("#btnApplictions").removeClass("btnApplictionsActive");
				$("#subMenuApplications").hide();

		});
		
		
		/* Markets */
		var timeoutMarket;
		//$("#subMenuMarkets").hide();
		$("#btnMarkets").unbind('mouseover').mouseover(function() {
			Alcad.Nav2.closeMenu();
			$("#subMenuMarkets").show();
			$("#btnMarkets").addClass("btnMarketsActive");
			clearTimeout(timeoutMarket);
		});

		$("#subMenuMarkets").unbind('mouseover').mouseover(function() {
			$("#btnMarkets").addClass("btnMarketsActive");
			$("#subMenuMarkets").css({'display' : 'block'});
			clearTimeout(timeoutMarket);
		});
		
		$("#subMenuMarkets").unbind('mouseout').mouseout(function() {
			timeoutMarket = setTimeout(function(){
				
				$("#subMenuMarkets").css({'display' : 'none'});
				$("#btnMarkets").removeClass("btnMarketsActive");
				
			}, 1500);
		});
		
		$("#btnMarkets").unbind('mouseout').mouseout(function() {			

				$("#btnMarkets").removeClass("btnMarketsActive");
				$("#subMenuMarkets").hide();

		});
		
		
		/* Products */
		var timeoutProduct;
		//$("#subMenuProducts").hide();
		
		$("#btnProducts").unbind('mouseover').mouseover(function() {
			Alcad.Nav2.closeMenu();
			$("#subMenuProducts").show();
			$("#btnProducts").addClass("btnProductsActive");
			clearTimeout(timeoutProduct);
		});

		$("#subMenuProducts").unbind('mouseover').mouseover(function() {
			$("#btnProducts").addClass("btnProductsActive");
			$("#subMenuProducts").css({'display' : 'block'});
			clearTimeout(timeoutProduct);
		});
		
		$("#subMenuProducts").unbind('mouseout').mouseout(function() {
			timeoutProduct = setTimeout(function(){
				$("#subMenuProducts").css({'display' : 'none'});
				$("#btnProducts").removeClass("btnProductsActive");
			}, 1500);
		});
		
		$("#btnProducts").unbind('mouseout').mouseout(function() {

				$("#btnProducts").removeClass("btnProductsActive");
				$("#subMenuProducts").hide();

		});
		
		/* Service */
		var timeoutService;
		//$("#subMenuServices").hide();
		$("#btnServices").unbind('mouseover').mouseover(function() {
			Alcad.Nav2.closeMenu();
			$("#subMenuServices").show();
			$("#btnServices").addClass("btnServicesActive");
			clearTimeout(timeoutService);
		});

		$("#subMenuServices").unbind('mouseover').mouseover(function() {
			$("#btnServices").addClass("btnServicesActive");
			$("#subMenuServices").css({'display' : 'block'});
			clearTimeout(timeoutService);
		});
		
		$("#subMenuServices").unbind('mouseout').mouseout(function() {
			timeoutService = setTimeout(function(){
				$("#subMenuServices").css({'display' : 'none'});
				$("#btnServices").removeClass("btnServicesActive");
			}, 1500);
			
		});
		
		$("#btnServices").unbind('mouseout').mouseout(function() {

				$("#btnServices").removeClass("btnServicesActive");
				$("#subMenuServices").hide();

		});
		
		/* Download center */
		var timeoutDownload;
		//$("#subMenuDownloadCenter").hide();
		
		$("#btnDownloadCenter").unbind('mouseover').mouseover(function() {
			Alcad.Nav2.closeMenu();
			
			$("#subMenuDownloadCenter").show();
			$("#btnDownloadCenter").addClass("btnDownloadCenterActive");
			clearTimeout(timeoutDownload);
		});

		$("#subMenuDownloadCenter").unbind('mouseover').mouseover(function() {
			$("#btnDownloadCenter").addClass("btnDownloadCenterActive");
			$("#subMenuDownloadCenter").css({'display' : 'block'});
			clearTimeout(timeoutDownload);
		});
		
		$("#subMenuDownloadCenter").unbind('mouseout').mouseout(function() {
			timeoutDownload = setTimeout(function(){
				
				$("#subMenuDownloadCenter").css({'display' : 'none'});
				$("#btnDownloadCenter").removeClass("btnDownloadCenterActive");
				
			}, 2000);
		});
		
		$("#btnDownloadCenter").unbind('mouseout').mouseout(function() {
			$("#btnDownloadCenter").removeClass("btnDownloadCenterActive");
			$("#subMenuDownloadCenter").hide();

			
		});
	
		/* Common */
		$(".linkNav2SubMenu1").unbind('mouseover').mouseover(function() {
			$(".blockNav2SubMenu1 .submenu").hide();
			$(this).next('.submenu').show();
			
		});
		
		$(".linkNav2SubMenu1 .submenu").unbind('mouseout').mouseout(function() {
			$(this).next('.submenu').hide();
		});
	}
		
		
};

Alcad.Search = {
	
	setFilter: function(type){
		$("#block2AdvancedResearchForm input[name=filter]").val(type);
		$("#block2AdvancedResearchForm").submit();
		
		return false;
	},
	listProduct: function(category_node){
		$('#ajaxProductSelect').load('/layout/set/ajax/ajax/search_products_category/'+category_node);
	},
	setOffset: function(offset){
		$("#block2AdvancedResearchForm input[name=offset]").val(offset);
		$("#block2AdvancedResearchForm").submit();
    
		return false;
	}
	
}


Alcad.Glossary = {
	initialize: function(){

		$(".block2TechnicalGlossaryBlockDisplayLink").toggle(function(){
			
			$(".block2TechnicalGlossaryBlockBottomHidden").slideUp();
			
			var thisDom = $(this);
			thisDom.parent().next().slideDown();
			
			return false;
			
		},
		function(){
			$(".block2TechnicalGlossaryBlockBottomHidden").slideUp();
			
			var thisDom = $(this);
			thisDom.parent().next().slideUp();
			
			return false;
		});
	}
	
}

Alcad.Alert = {
	initialize: function(){
		$(".emailAlertOpen").click(function(){
			Lightbox.open('/layout/set/ajax/tools/email-alert/');
			return false;
		});
		
		$(".internationalAlertOpen").click(function(){
			Lightbox.open('/layout/set/ajax/ajax/zones/open','Alcad.Common.initialize()');
			return false;
		});
		
	}
}

	
$().ready(function() {
	
	/* Common */
	Alcad.Common.initialize();
	
	Alcad.Nav2.initialize();
	
	Alcad.Carousel.initialize();
	
	Alcad.Category.initialize();
	
	Alcad.Alert.initialize();
});
