$(document).ready(function(){

	helpdesk.operate();
	scrollTop.trigger();
	cufon.init();
	iPad.detection();
	hover.active();
	slideshow.innerfade();
	checkbox.clicked();
	selector.dial();
	hoverWrap.active();
	temoignage.init();
	construction.shout();

});
 var navClass = $(this).attr("class"),
					navId = "#"+navClass;
					
var helpdesk = {
	operate:function(){
			if((navigator.userAgent.match(/iPad/i))) {
			$(".helpdeskNavigation li a").click(function() {
			alert("UNDER CONSTRUCTION!!");})
			}else{
			$(".helpdeskNavigation li a").click(function() {
		  	/*if( $(this).parent().hasClass('active') ) {
				$(this).parent().removeClass('active');
				$(".helpdeskWrapper").stop(true,true).slideUp(600,"easeInQuart");
				
			} else{
				$(this).parent().addClass('active');
				$(".helpdeskWrapper").stop(true,true).slideDown(600,"easeOutQuart");
			}*/
			alert("UNDER CONSTRUCTION!!");
		});
		}
	}
}

var scrollTop = {
	trigger:function(){
		$(".scrollTop").click(function() {
			var helpdeskWrapperTop = $(".helpdeskWrapper").offset().top-20;
			var mainpageWrapperTop = $(".mainpageWrapper").offset().top;
			
		  	if( $(".helpdeskNavigation li").hasClass('active') ) {
					$('html, body').stop(true,true).animate({scrollTop:helpdeskWrapperTop}, 800,'easeOutQuart');				
				} else{
					$('html, body').stop(true,true).animate({scrollTop:mainpageWrapperTop}, 800,'easeOutQuart');					
				}
		});
	}
}

var cufon = {
	init:function(){
		Cufon.replace('h1,h2,h3,.selector,h4, h5');
		Cufon.replace(('.hoverWrap h2'),{textShadow: '1px 1px 0 #161415'});
		Cufon.replace('legend,#send, label');
		Cufon.replace (".middleContents");
		Cufon('.menu', {textShadow: '1px 1px #000',
	hover: {
		color: '#999'
	}});
			
}}

var iPad = {
	detection:function(){
	 	  if((navigator.userAgent.match(/iPad/i))) {
   			$(".scrollTop").css("display","none");
		}
}}

var hover = {
	active:function(){
	$(".tags li").hoverIntent(function(){
			$(this).addClass("active");	
		},
		function(){
			$(this).removeClass("active");
		});
	}
}

var hoverWrap = {
	active:function(){
	$(".pageNavigation li").hoverIntent(
			function(){
				var navClass = $(this).attr("class"),
					navId = "#"+navClass;
					
				if($(this).hasClass("home")){
						$(this).addClass("active");
					}else if($(navId).length===0){
						return false;			
					}else{	
						$(this).addClass("active");		
					}
			},
			function(){
				$(this).removeClass("active");				
			});
	
		$(".pageNavigation li:not(.disabled)").click(
			function(){
				var navClass = $(this).attr("class");
					navId = "#"+navClass,
					newId = navId.replace("active",""),
					pageNavigation = $(this).parent(),
					mainPage = $(this).parent().parent().parent();

						if($(this).hasClass("selected")){
							$(this).removeClass("selected");
							$(".hoverWrap").slideUp();
						}else{
							pageNavigation.find("li.selected").removeClass("selected");
							$(".hoverWrap").find("div.active").removeClass("active");
							$(this).addClass("selected");
							mainPage.find(newId).addClass("active");
							$(".hoverWrap").slideDown();
						}
			});
			
			$(".hoverClose").click(
			function(){	
				$(".hoverWrap").slideUp();	
				mainPage.find("li.selected").removeClass("selected");
			});
	}
}

var slideshow = {
	innerfade:function(){
		$('.innerfade').innerfade({
			 speed: 'slow', timeout: 6000, type: 'sequence', containerheight: '537px' 
		});	
	}
}

var checkbox = {
	clicked:function(){
		$(".checkbox").click(function(){
			if( $(this).hasClass('active') ) {
					$(this).removeClass('active');					
				} else{
					$(this).addClass('active');
				}
		});
	}
}

var selector = {
	dial:function(){
	$(".helpdeskSelector").hover(function(){
			$(this).parent().find(".active").removeClass("active");
			$(this).find(".selector").addClass("active");
			
		},
		function(){}
		);
	}
}

var temoignage = {
	
	init:function(){
		$('.temoignage-details').hide();
		
		$('.temoignage-wrapper').hoverIntent(function(){
			$(this).find('.temoignage-details').stop(true,true).slideDown( 400,'easeOutQuart');
		},function(){
			$(this).find('.temoignage-details').stop(true,true).slideUp();

		})
	}
}

var construction = {
	shout:function(){
		$(".pageContentRight .block a").click(function() {
			alert ("UNDER CONSTRUCTION!!!!")
		});
	}
}



var show = {
	menu:function(){
		$(".menu").fadeIn(1000);
	}
}

var lightview = {
	library:function(){		
		$('.contact').click(function() {
			if ($(this).hasClass("selected")){
				$(this).removeClass("selected");
				$('.library-Contents').hide();
			}else{
				$(this).addClass("selected");
				$('.library-Contents').show();
				Cufon.refresh();
				$(".lightviewWrapper>cufon").remove();
				$(".middleContents>cufon").remove();
			}
		});
		
		$("a.close").click(function() {		
		if ($("a.contact").hasClass("selected")){
			$("a.contact").removeClass("selected");
			$('.lightviewWrapper').hide();	
		}			
	});
	}	
};

var space = {
	remove:function(){
		$(".menu>cufon").remove();
		}
};

var remove ={
	bg:function(){
	$(".pageContentLeft .article:last").css("background","none")
	}
};

var under = {
	dev:function(){		
			$('.library-Contents').show();
			Cufon.refresh();
			$(".lightviewWrapper>cufon").remove();
			$(".middleContents>cufon").remove();
		
		$("a.close").click(function() {		
			$('.lightviewWrapper').hide();});
	}	
};


var dynamic = {
	position:function(){
	var windowHeight = $(window).height();
	var centerY = windowHeight/2;

	var sgHeight =  $(".southGate").height();
	var sgCenterY = sgHeight/2;

	var topCoordinate = centerY - sgCenterY;
	$(".southGate").css("top",topCoordinate);
	}
};

/*var anim = {
	subMenuOpen:function(){
		$("#main-nav > ul > li").hoverIntent(
				function(){
					 $(this).find("ul").stop(true, true).slideDown({duration:400, easing:"easeInQuart"});
					 $(this).find("ul").css('min-width',$(this).outerWidth());
				},
				function(){
					$(this).find("ul").slideUp();
				});
	},//  subMenuOpen
	
	siteMenuOpen:function(){
		$("#topnav > ul > li").hoverIntent(
				function(){
					$(this).outerWidth();
					 $(this).find("ul").stop(true, true).slideDown({duration:400, easing:"easeInQuart"});
					 // $(this).find("ul").css('width',$(this).outerWidth());
				},
				function(){
					$(this).find("ul").slideUp();
				});
	}//  subMenuOpen
}

var clients = {	
	triggerBackground:function(){
		$('.client-list li').hover(
			function(){
				$(this).css({'background-color':'#333'})
			},function(){
				$(this).css({'background-color':'transparent'})

			});
	}
}

var sysnextmenu = {
	sysnext:function(){
		return $('#sysnext-menu');
	}, 
	
	display:function() {
		this.sysnext().stop('true').animate({'left':'0px'})
	}, 
	dock:function(){
		var offset = this.sysnext().outerWidth()-20;
		//console.log(offset);
		this.sysnext().animate({'left':'-'+offset+'px'})
	}, 
	trigger:function(){
		setTimeout('sysnextmenu.dock()', 1000) //Makes the sysnext menu dock after 0.5 seconds so that the user notices it

		this.sysnext().hover(function(){
			sysnextmenu.display();
		},function(){
			sysnextmenu.dock();
		})
	}
}

var easySliders = {	
	examplesSlider:function(){
		$("#examples-slider").easySlider({
			prevId: 'prevBtn-ex',
			nextId: 'nextBtn-ex',
			controlsShow: false
		});
	},
	evenementSlider:function(){
		$("#evenment-slider").easySlider({
			prevId: 'prevBtn-ev',
			nextId: 'nextBtn-ev',
			auto: true,
			continuous: true,
			controlsShow: false
		});
	},
	middleContentSlider:function(){
		$("#middle-article-slider").easySlider({
			prevId: 'prevBtn-news',
			nextId: 'nextBtn-news',
			controlsShow: false,
			//orientation: 'horizontal',
			vertical: true
		});
	},
	productSlider:function(){
		$("#product-slider").easySlider({
			prevId: 'prevBtn-prod',
			nextId: 'nextBtn-prod',
			controlsShow: false
			//orientation: 'horizontal',
		});
	},
	configSliders:function(){
		$('#slider-config-product-1').easySlider({
			prevId: 'prev-slider-config-product-1',
			nextId: 'next-slider-config-product-1',
			controlsShow: false
		});
		$('#slider-config-product-2').easySlider({
			prevId: 'prev-slider-config-product-2',
			nextId: 'next-slider-config-product-2',			
			controlsShow: false
		});
		$('#slider-config-product-3').easySlider({
			prevId: 'prev-slider-config-product-3',
			nextId: 'next-slider-config-product-3 ',			
			controlsShow: false
		});
	}
}

var cufon = {
	init:function(){
		Cufon.replace('h1:not(.clean)', {
		textShadow: '1px 0px 0px #000',
		letterSpacing: '-2px'
	});
		
		Cufon.replace('h2:not(.clean)', {
		textShadow: '1px 0 0 #000',
		letterSpacing: '-2px',
		'line-height': '30px'
	});
	
		Cufon.replace('h3:not(.clean)', {
		textShadow: '1px 0px 0px #000',
		letterSpacing: '-1px'
	});
		Cufon.replace('h4:not(.clean)', {
		textShadow: '1px 0px 0px #000',
		letterSpacing: '-1px'
	});
		Cufon.replace('.grandTitre', {
		textShadow: '1px 0px 0px #000',
		letterSpacing: '-1px'
	});
	
		Cufon.replace('.cufonize');	
		
		Cufon.replace('.subHeading', {
		textShadow: '1px 0px 0px #000',
		letterSpacing: '-1px'
	});
	
	Cufon.replace('.sidebarMenuTitle', {
		textShadow: '1px 0px 0px #000',
		letterSpacing: '-1px'
	});
	
	Cufon.replace('.specifications', {
		textShadow: '1px 0px 0px #000',
		letterSpacing: '-1px'
	});
	
	Cufon.replace('.searchReseller h3', {
		textShadow: '1px 0px 0px #000',
		letterSpacing: '-1px',
		color: '#fff'
	});
	
	
	}
}


var formStyles = {
	
	init:function(){ 									//radiobuttons
			$(".radioButtonAlt, .radioButtonAlt2").click(function() {
			$(this).parent().parent().find('.radioSelected').removeClass('radioSelected');
			$(this).addClass('radioSelected');
			});	
			
			$(".checkboxAlt").click(function() { 			//Checkboxes
				if( $(this).hasClass('checkboxSelected') ) {
					$(this).removeClass('checkboxSelected');
				} else{
					$(this).addClass('checkboxSelected');
				}
			});
			

		},
		
		selectGenerator:function(){ //generates the additional markup for all select boxes
			$(".selectdrop").find('span').live('click',(function(){				//selectBoxes
				//console.log($(this).outerWidth()-27);
				$(this).next('ul').slideDown();
				
				$(this).next('ul').find('li').css({'width':$(this).outerWidth()-27+'px'});
			}));
			
			$('.selectdrop > ul > li').live('click',(function(){ //displays the dropdown
				var me = $(this);
				var hidden = $('#' + me.parent().attr('id').substr(10));
				//console.log(hidden);
				hidden.val(me.attr('title'));
				
				me.parent().parent().find('span').html($(this).html());
				//console.log($(this).attr('id'));
				var id = me.parent().parent().children('select').attr('id');
				//console.log(id);
				//document.getElementById('moi').setAttribute('selected','selected');
				//$('option[2]').attr({"selected":"selected"});
			})
			);
			
			$().click(function(){  //hides the dropdown
				$('.selectdrop > ul').hide();
			});			
			$
			
			$('.commonForm').find('select').each(function(){
				//wrap in div
				$(this).wrap('<div class="selectdrop" />');
					//add new div
				var p = $(this).parent()[0];
				var ul = document.createElement("ul");
				if(this.id == ''){
					this.id = 'bs' + this.name;
				}
				ul.id = "bs-select-" + this.id;
				// ul.parent().wrap('<div class="viewport" />');
				// ul.parent().parent().wrap('<div id="scrollbar1" />');
				// ul.parent().parent().append('<div class="scrollbar"><div class="track"><div class="thumb"><div class="end"></div></div></div></div>');	
// 		
				
				var span = document.createElement("span");
				
				var first = true;
				$(this).find('option').each(function(index){
					var li = document.createElement('li');
					li.innerHTML = $(this).html();
					var myindex = index;
					var id = $(this).parent().attr('name')+index;
					var value = $(this).attr('value');
					//console.log($(this).attr('value'));
					//console.log(value);
					if(first){
						first = false;
						span.innerHTML = $(this).html();
					}else{
						li.id = id;
						li.title = value;
						ul.appendChild(li);
					}
				});
				p.appendChild(span);
				p.appendChild(ul);
				// var hidden = document.createElement('input');
				// hidden.type = 'hidden';
				// var h = $(hidden);
// 				
				// $(this.attributes).each(function(){
					// h.attr(this.name,this.value);
				// });
// 				
				// parent = this.parentNode;
				// parent.removeChild(this);
				// parent.appendChild(hidden);
			})
		}
}

$(window).ready(function(){
	$('#backtotop').click(function(e){
	e.preventDefault();
	$('html, body').animate({scrollTop:0}, 'slow');
	});
});


var temoignage = {
	
	init:function(){
		$('.temoignage-details').hide();
		
		$('.temoignage-wrapper').hover(function(){
			console.log('stuff happening');
			$(this).find('.temoignage-details').stop(true,true).slideDown( 400,'easeOutQuart');
		},function(){
			$(this).find('.temoignage-details').stop(true,true).slideUp();

		})
	}
}

var joblist = {
	
	init:function(){
		$(".jobVacancyRight a").click(function () {
		if( $(this).hasClass('open') ) {
			$(this).removeClass("open");
			$(this).parent().parent().parent().find('.jobDescription-wrapper').slideUp(600,'easeOutQuart');
		} else{
			$(this).addClass("open");
			$(this).parent().parent().parent().find('.jobDescription-wrapper').slideDown( 600,'easeOutQuart');
		}
	});	
		
	}
}*/
