jQuery.noConflict();

String.prototype.contains = function(str){
	return this.indexOf(str) > -1;
}

var Symentis = {
    init: function(){
				// main navigation
        jQuery('.nav .fade a').fadeTo(0, .4).hover(function(){
            jQuery(this).animate({
                opacity: 1
            }, 300, 'easeOutSine')
        }, function(){
            jQuery(this).animate({
                opacity: .4
            }, 300, 'easeOutSine')
        })
				.click(function(){jQuery(this).css('opacity', .4)});
				// sub navigation
				if (!window.location.href.contains('#')) {
					jQuery('.active li a').fadeTo(0, 0);
					jQuery('.active .active a').fadeTo(500, 1);
				} else {
					jQuery('.active .fade a').fadeTo(0, 1);
				}
				jQuery('.active .fade a').fadeTo(500, 0.4)
        // footer
        jQuery('.footer a').hover(function(){
            jQuery(this).animate({
                color: "#000"
            }, 300, 'easeOutSine')
        }, function(){
            jQuery(this).animate({
                color: "#757363"
            }, 300, 'easeOutSine')
        })
				.click(function(){jQuery(this).css('color', '#757363')});
				//
				// jQuery('.needle').rotateAnimation(360);
				jQuery('.sym1').click(function(){w = window.open('mailto:info' + '@' + 'symentis.com','');w.close();});
				jQuery('.sym1w').click(function(){w = window.open('mailto:info' + '@' + 'symentis.com','');w.close();});
				//
				jQuery('.print').click(function(){window.print();})
				//
				if(jQuery('body').hasClass('gallery')){
					Symentis.Gallery.init();
				}
	   },
	 Gallery: {
		 selected: 1,
		 total: 0,
		 isAnimating: false,
		 doneAnimation: function(){
		 	Symentis.Gallery.isAnimating = false;
		 },
		 init: function(){
				jQuery('body').addClass('galleryLoaded');
		 		//
				var staticControl = jQuery('#ref1 .control').detach().appendTo('.header').addClass('staticControl').removeClass('control');				
				jQuery('.front').removeAttr('href'); 
				jQuery('.back').removeAttr('href'); 
				jQuery('.ref').css('opacity', 0);
				jQuery('#ref1').css('opacity', 1);
			  Symentis.Gallery.total = jQuery('.ref').size();
				//
				var marginLeftStart = Symentis.Gallery.getLeftPx(Symentis.Gallery.selected);
				//
				jQuery('#area').animate({left: marginLeftStart}, 0);
				//
				jQuery('.front').click(function(){
					if (Symentis.Gallery.isAnimating) return;
					//
					jQuery('#ref' + Symentis.Gallery.selected).animate({opacity: 0}, 500, 'easeInOutSine');
					//
					if ((Symentis.Gallery.selected + 1 ) > Symentis.Gallery.total) {
						Symentis.Gallery.selected = 1;
					} else {						
						Symentis.Gallery.selected++;
					}
					Symentis.Gallery.isAnimating = true;
					//
					var marginLeftPx = Symentis.Gallery.getLeftPx(Symentis.Gallery.selected);
					//
					jQuery('#area').animate({left: marginLeftPx}, 750, 'easeInOutSine');
					//
					jQuery('#ref' + Symentis.Gallery.selected).animate({opacity: 1}, 750, 'easeInOutSine',Symentis.Gallery.doneAnimation );
					return false;
				})
				jQuery('.back').click(function(){
					if (Symentis.Gallery.isAnimating) return;
					//
					jQuery('#ref' + Symentis.Gallery.selected).animate({opacity: 0}, 500, 'easeInOutSine');
					//
					Symentis.Gallery.isAnimating = true;
					if ((Symentis.Gallery.selected - 1 ) < 1){
						Symentis.Gallery.selected = Symentis.Gallery.total;
					} else {
						Symentis.Gallery.selected--;						
					}
					//
					var marginLeftPx = Symentis.Gallery.getLeftPx(Symentis.Gallery.selected);
					//
					jQuery('#area').animate({left: marginLeftPx}, 750,'easeInOutSine');
					//
					jQuery('#ref' + Symentis.Gallery.selected).animate({opacity: 1}, 750, 'easeInOutSine', Symentis.Gallery.doneAnimation );
					return false;
				})
		 },
		 getLeftPx: function(refNumber){
		 		var marginLeft = 5020 - (1000 * (refNumber - 1));
				return marginLeft + 'px';  
		 }
	}
}

jQuery(document).ready(Symentis.init);
