jQuery.noConflict();

jQuery(function() {
	/* INPUT FIELDS */
	if(jQuery(".search-box input:text").length>0){
		jQuery(".search-box input:text").attr("value", "Search");
		jQuery(".search-box input:text").focus(function() {
			if(jQuery(".search-box input:text").attr("value")=="Search"){
  				jQuery(".search-box input:text").attr("value", "");
			}
		});
		jQuery(".search-box input:text").blur(function() {
			if(jQuery(".search-box input:text").attr("value")==""){
	  			jQuery(".search-box input:text").attr("value", "Search");
			}
		});
	}


	jQuery('#overlay').click(function() {
		jQuery('#logDiv2').fadeOut(500, function() {
			jQuery('#overlay').fadeOut(500);
		});
	});
	
	jQuery('.btn-close').click(function() {
		jQuery('#logDiv2').fadeOut(500, function() {
			jQuery('#overlay').fadeOut(500);
		});
		return false;
	});
	//select all the a tag with name equal to modal
	jQuery('.openDialog').click(function(e) {
		// show the dialog
		jQuery('#overlay').fadeIn(500, function() {
			jQuery('#logDiv2').fadeIn(500);
		});
		//Cancel the link behavior
		e.preventDefault();
		
		//Get the A tag
		var id = "#logDiv2";
	
		//Get the window height and width
		var winH = jQuery(window).height();
		var winW = jQuery(window).width();
        
		//Set the popup window to center
		if (winH/2-jQuery(id).height()/2 > 0)
			jQuery(id).css('top',  winH/2-jQuery(id).height()/2 + jQuery(window).scrollTop());
		else
			jQuery(id).css('top',  10  + jQuery(window).scrollTop());
			
		if (winW/2-jQuery(id).width()/2 > 0)
			jQuery(id).css('left', winW/2-jQuery(id).width()/2  + jQuery(window).scrollLeft());
		else
			jQuery(id).css('left', 10  + jQuery(window).scrollLeft());
			
		//Get the screen height and width
		//var maskHeight = jQuery(document).height();
		//var maskWidth = jQuery(document).width();
	
		//Set heigth and width to mask to fill up the whole screen
		//jQuery('#mask').css({'width':maskWidth,'height':maskHeight});
		
		//transition effect		
		//jQuery('#mask').fadeIn(1000);	
		//jQuery('#mask').fadeTo("slow",0.8);	
	
		//transition effect 
		//jQuery(id).fadeIn(2000);
		
		
		//Do it again to fix
		//Get the screen height and width
		//var maskHeight = jQuery(document).height();
		//var maskWidth = jQuery(document).width();
	
		//Set heigth and width to mask to fill up the whole screen
		//jQuery('#mask').css({'width':maskWidth,'height':maskHeight});
	
	});
	
	jQuery(window).resize(function() {
		
		//Get the A tag
		var id = "#logDiv2";
	
		//Get the window height and width
		var winH = jQuery(window).height();
		var winW = jQuery(window).width();
              
		//Set the popup window to center
		if (winH/2-jQuery(id).height()/2 > 0)
			jQuery(id).css('top',  winH/2-jQuery(id).height()/2 + jQuery(window).scrollTop());
		else
			jQuery(id).css('top',  10  + jQuery(window).scrollTop());
			
		if (winW/2-jQuery(id).width()/2 > 0)
			jQuery(id).css('left', winW/2-jQuery(id).width()/2  + jQuery(window).scrollLeft());
		else
			jQuery(id).css('left', 10  + jQuery(window).scrollLeft());

		//Get the screen height and width
		var maskHeight = jQuery(document).height();
		var maskWidth = jQuery(document).width();

		//Set heigth and width to mask to fill up the whole screen
		//jQuery('#logDiv2').css({'width':maskWidth,'height':maskHeight});

	});

	/* FAQ */
	if(jQuery(".faq li").length>0){
		var numOfFaq = jQuery(".faq li").length;
		var visibleFaq = 2;
		var numOfSlide = Math.ceil(numOfFaq/visibleFaq);
		var currentFaq = 0;
		jQuery(".faq li").hide();
		for(var i=0; i<visibleFaq; i++){
			jQuery(".faq li").eq(i).show();
		}
		
		jQuery(".faq li").oneTime(10000, "updateFaq", function() { 
			updateFaq(numOfSlide, visibleFaq, currentFaq);		
		});
		
		function updateFaq(numOfSlide, visibleFaq, currentFaq){
			jQuery(".faq li").stopTime("updateFaq");
			
			if((currentFaq+1)<numOfSlide){
				currentFaq++;
			} else {
				currentFaq=0;
			}
			
			jQuery(".faq li").hide();
			jQuery(".faq li").eq(currentFaq*visibleFaq).fadeIn(1000);
			jQuery(".faq li").eq(currentFaq*visibleFaq+1).fadeIn(1000);
			
			jQuery(".faq li").oneTime(10000, "updateFaq", function() { 
				updateFaq(numOfSlide, visibleFaq, currentFaq);		
			});
		}
	}

	/* NAVIGATION */			
	
	var $el, leftPos, newWidth,
        $mainNav = jQuery(".main-nav");
    
    if(jQuery(".current_page_item").length>0){
		$mainNav.append("<li id='magic-line'></li>");
		
		var $magicLine = jQuery("#magic-line");
    
	
		$magicLine
			.width(jQuery(".current_page_item").width())
			.css("left", jQuery(".current_page_item a").position().left)
			.data("origLeft", $magicLine.position().left)
			.data("origWidth", $magicLine.width());
        
		jQuery(".main-nav li").find("a").hover(function() {
			$el = jQuery(this);
			leftPos = $el.position().left;
			newWidth = $el.parent().width();
			
			$magicLine.stop().animate({
				left: leftPos,
				width: newWidth
			});
		}, function() {
			$magicLine.stop().animate({
				left: $magicLine.data("origLeft"),
				width: $magicLine.data("origWidth")
			});    
		});
	}
	
	/* NAVIGATION END */
	
	/* newsticker */
	jQuery(".newsticker-jcarousellite").jCarouselLite({
		vertical: true,
		hoverPause:true,
		visible: 2,
		auto:3000,
		speed:1000
	});
	
	/* SLIDER */
	if(jQuery('.slider ul li').length>0){
		var maxItems = jQuery('.slider ul li').length;
		var visibleItems = 5;
		var slides = Math.ceil(maxItems/visibleItems);
		var currentSlide = 1;
		var currentPosition = 0;
		
		if(currentSlide==1){
			jQuery('.home-slider .btn-prev').css('visibility', 'hidden');
		}
		if(currentSlide==slides){
			jQuery('.home-slider .btn-next').css('visibility', 'hidden');
		}
		
		jQuery('.home-slider .btn-next').click(function() {
			currentSlide++;
			if(currentSlide!=1 && currentSlide!=slides && slides!=1){
				jQuery('.home-slider .btn-prev').css('visibility', 'visible');
				jQuery('.home-slider .btn-next').css('visibility', 'visible');
			}
			if(currentSlide==1 && slides!=1){
				jQuery('.home-slider .btn-prev').css('visibility', 'hidden');
				jQuery('.home-slider .btn-next').css('visibility', 'visible');
			} 
			if(currentSlide==slides && slides!=1){
				jQuery('.home-slider .btn-next').css('visibility', 'hidden');
				jQuery('.home-slider .btn-prev').css('visibility', 'visible');
			}
			
			jQuery('.slider ul').animate({"left": "-=985px"}, "slow");
			return false;
		});
		
		jQuery('.home-slider .btn-prev').click(function() {
			currentSlide--;
			if(currentSlide!=1 && currentSlide!=slides && slides!=1){
				jQuery('.home-slider .btn-prev').css('visibility', 'visible');
				jQuery('.home-slider .btn-next').css('visibility', 'visible');
			}
			if(currentSlide==1 && slides!=1){
				jQuery('.home-slider .btn-prev').css('visibility', 'hidden');
				jQuery('.home-slider .btn-next').css('visibility', 'visible');
			} 
			if(currentSlide==slides && slides!=1){
				jQuery('.home-slider .btn-next').css('visibility', 'hidden');
				jQuery('.home-slider .btn-prev').css('visibility', 'visible');
			}
			jQuery('.slider ul').animate({"left": "+=985px"}, "slow");
			return false;
		});
	}
	
	/* PRETTYPHOTO */
	if(jQuery(".gallery").length>0) {
		var itemWidth = 0;
		var top_margin = 0;
		var maxNumItems = jQuery(".gallery li").length;
		for( var i=0; i<maxNumItems; i++) {
			itemWidth = jQuery('.gallery li:eq('+i+') img').attr('width');
			itemHeight = jQuery('.gallery li:eq('+i+') img').attr('height');
			top_margin = (130 - itemHeight)/2;
			jQuery('.gallery li:eq('+i+') img').css('margin-top', top_margin);
		}
		jQuery(".gallery a[rel^='prettyPhoto']").prettyPhoto({theme: 'facebook'});
	}
	
	/* TABBER */
	if(jQuery(".tabber").length>0) {
		var visibleTab = 0;
		jQuery(".tabber .tabber-content").hide();
		jQuery(".tabber .tabber-content").eq(visibleTab).show();
		jQuery(".tabber-nav li").eq(visibleTab).addClass('active');
		
		jQuery('.tabber-nav li a').click(function() {
			var clickedTab = jQuery(this).parents('li').index();
			if(!jQuery(this).parents('li').hasClass('active')){
				jQuery(".tabber-nav li").removeClass('active');
				jQuery(".tabber-nav li").eq(clickedTab).addClass('active');
				
				jQuery(".tabber .tabber-content").hide();
				jQuery(".tabber .tabber-content").eq(clickedTab).show();
			}
			return false;
		});
	}
	
	// jQuery SmoothScroll | Version 10-04-30
	jQuery('a.jttop').click(function() {
	   // duration in ms
	   var duration=1000;

	   // easing values: swing | linear
	   var easing='swing';

	   // get / set parameters
	   var newHash=this.hash;
	   var target=jQuery(this.hash).offset().top;
	   var oldLocation=window.location.href.replace(window.location.hash, '');
	   var newLocation=this;

	   // make sure it's the same location      
	   if(oldLocation+newHash==newLocation)
	   {
	      // animate to target and set the hash to the window.location after the animation
	      jQuery('html:not(:animated),body:not(:animated)').animate({ scrollTop: target }, duration, easing, function() {

	         // add new hash to the browser location
	         window.location.href=newLocation;
	      });

	      // cancel default click action
	      return false;
	   }
	});

});		   
