
	var isModernBrowser = document.createElement('canvas').getContext;
	
	//slider bekleme zamanı
	var slideTime = 4000;
	
	
	//******************* FONT REPLACEMENT
	//********************************************************
	
	//Cufon Font Replacement			
	Cufon.replace('h2, h3, h4, #slider div#thumbs ul li p span.title' , { hover: isModernBrowser,fontFamily: 'PT Sans' }); 
	//baslik icinde bold yazilar
	Cufon.replace('h2 b, h3 b, h4 b, #news-list div h4, #logos a span.title, #slider div#thumbs ul li p span.title b' , { hover: isModernBrowser, fontFamily: 'PT Sans Bold' });
		
	//******************* FONT REPLACEMENT
	//********************************************************
	
	

$(function() {
		
		
		//**********************************
		//UPDATE v1.4
		$('ul.albums li a.big').append('<span class="mask"></span>');
		$('.pagination').addClass('album-paging');
		//UPDATE v1.4
		//**********************************
		
		
		
		//**********************************
		// FIXED MENU
		
		//sticky float menu
		$('#fixed-menu').stickyfloat({ duration: 1200, lockBottom:false, startOffset:216, offsetY:116, easing:'easeOutExpo' });
		
		//scroll to top
		$('a#up').click(function(){
			$('html, body').stop(true,true).animate({scrollTop:0}, 800,'easeOutCirc');
			return false;
		});
		
		//print
		$('a#print').click(function(){
			window.print();
			return false;
		});
		//**********************************
		
		
		
		
		 //**********************************
		 // FOOTER LOGOS
		 	makeLogosScrollable();
			playLogos();
			
			$('#logos a').hover(function() {
				
				//console.log($('#logos').scrollLeft());
				
				clearInterval(playLogo);
				
				var title = $(this).find('.title');
				var logo = $(this).find('.logo');
				
				if(isModernBrowser) {
					title.stop(true,true).fadeTo(200,0);
					//logo.show();
					logo.stop(true,true).slideDown(600);
				} else {
					title.css('visibility','hidden');
					logo.slideDown(600);	
				}
				
				}, function() {	  //hover out
					
					playLogos();
					
					var title = $(this).find('.title');
					var logo = $(this).find('.logo');
						
					if(isModernBrowser) {
						title.stop(true,true).fadeTo(800,1);
						logo.stop(true,true).fadeOut();
					} else {
						title.css('visibility','visible');
						logo.hide();	
					}	
			});
		 //**********************************
		
		 
		 
		 
		 //**********************************
		 // MAINPAGE GALLERY LINKS SCROLLBAR 
		 if($('#gallery-links').length) {
		 	$("#gallery-links").mCustomScrollbar("horizontal",500,"easeOutCirc",1.05,"180px","yes","yes",10);
		 }
		 //**********************************
		
		
		
		
		//**********************************
		// NEWS 
		//dinamik eklemeler
		$('#news-list div').each(function() {
			var index = $(this).index() + 1 ;
			if((index % 3) == 0 ) {
					$(this).addClass('no-border');
				}
			if(((index-2) % 3) == 0 ) {
					$(this).addClass('middle');
				}
			});
		//**********************************
		
		
		
		
		//**********************************
		// SIDEBAR 
		
		//dinamik eklemeler
		$('#sidebar ul').find('li:last').addClass('last');
		$('#sidebar ul li').each(function() {
			if($(this).find('ul').length) { $(this).addClass('has-sub-menu'); }
			});
		
		//Accordion Menu
		$('#sidebar ul li a').click(function() {
				
				//açık olan alt menüleri kapat.
				$(this).parent().siblings().find("ul").slideUp(300);
				$(this).parent().siblings().removeClass('selected');
				$(this).parent().siblings().find("a.active").removeClass('active');
				
				//alt menüsü varsa
				if($(this).parent().find('ul').length) {
					
					if($(this).parent().hasClass('selected')) {
						
						$(this).parent().removeClass('selected');
						$(this).removeClass('active');
						$(this).parent().find('ul:first').stop(true,true).slideUp(400);
						
					}
					else {
						$(this).addClass('active');
						$(this).parent().addClass('selected');
						$(this).parent().find('ul:first').stop(true,true).slideDown(500);
							
					}
					return false;
				}
				
			});
			
			//açılı olan içerik sayfasının menüsü açık dursun...	
			$('#sidebar ul li.selected ul:first').slideDown(1000);
		//**********************************
		
		
		
		//*************************************
		//validation
		if($('.validateForm').length) {
			$('.validateForm').each(function() {
					$(this).validate();
				});
			
		}
		//*************************************
		
		
		//**********************************
		// LIGHTBOX 
		if($('.lightbox').length) {
			$("a.lightbox").fancybox({'padding':8, 'margin':70, 'titlePosition':'over', 'centerOnScroll':true , 'overlayColor': '#000', 'overlayOpacity': '0.8'});
		}
		//**********************************
		
		
		//************************************* FIX V.1.2
		 // LIGTHBOX SHADOWBOX
		 if($('a[rel^=shadowbox]').length) {
			 Shadowbox.init({
				handleOversize: "drag",
				modal: true,
				counterType: 'skip',
				displayCounter: false,
				overlayColor: '#000',
				viewportPadding:40
			});
		 }
		 //************************************* FIX V.1.2
		 
		 
		
		//**********************************
		// BREADCRUMB 
		$('ul#breadcrumb li:last').addClass('active');
		//**********************************
		
		
		//**********************************
		//TABLE STYLING
		$('table tbody tr:even, ul#footer-nav li:odd').addClass('alt');
		
		//$('div#main-links.middle-links div#table table td')
		//**********************************
		
		
		//**********************************
		//FOOTER MENU ALT STYLING
		var liWidth = 180;
		var liHeight = 29;
		var half = Math.ceil($('ul#footer-nav li').length / 2 ); 
		//console.log(half);
		$('ul#footer-nav li').each(function() {
			var index = $(this).index();
			if(index < half ) {
				$(this).css('top', index*liHeight);
			} else {
				$(this).addClass('right').css('top', (index-half)*liHeight);	
			}
			});
		$('ul#footer-nav li:last').addClass('no-border');
		$('ul#footer-nav li').eq(half-1).addClass('no-border');
		//**********************************
		
		
		//**********************************
		//NAV MENU - SUB MENUS
		
		//image preload
		pic1= new Image(178,61); 
		pic1.src="images/bckg/nav-selected.png";
		
		$('#nav li').hover(function() {
				if($(this).find('ul').length) {
					$(this).find('a').eq(0).addClass("selected");
					$(this).find('ul:first').stop(true,true).slideDown(200);
				}
			}, function() {  //hover out
					$(this).find('a').eq(0).removeClass("selected");
					$(this).find('ul:first').stop(true,true).hide();
				});
		
		$('ul#nav ul').each(function() {
				$(this).find('li').last().addClass('last');
			});
		//**********************************
		
		
		
		
		//*************************************
		//input watermark
		$(".watermark").each(function (i) {
				$(this).watermark($(this).attr('title'), {className: "watermark",useNative: false});	
        });
		//*************************************
		
		
		
		
		
		
		
		
		
		//**************************************************
		//***************************************************
		//MAIN SLIDER
		
		//dinamik eklemeler
		$('#slider #thumbs li').append('<span class="mask"></span>');
		
		//video close button
		$('#slider').append('<a id="video-close">GALERİYE DÖN</a>');
		
		$('#slider #preview').addClass('loading');
		
		//make thumbs scrollable on mouse move
		makeScrollable("div#thumbs", "div#thumbs ul");
		
		//scroll to selected gallery on mouse leave
		$('div#thumbs').hover(function(){
				scroll = false;
			},function() {
				scroll = true;
				scrollToGallery();
				});
		
		//thumbnailllere tıklanınca
		$("#slider #thumbs li").click(function(){ 
			goToGallery($(this));
		});
		
		
		
		//thumbnaillere tıklanınca
		$("#slider #paging a").live('click', function() {
				
				if($(this).hasClass('active')) 
					return;
					
				//stop slider and clear interval - reset timer
				clearInterval(play);
				
				$(this).siblings().removeClass('active');
				$(this).addClass('active');
				
				var div = $('#slider #preview div.slider-item').eq($(this).index());
				
				//Slider Animation
				goToSlide(div);
				
				if(!$('#slider a#play').hasClass('paused')) {
					//start slider
					rotateSwitch();
				}
				
			});
		
		//play-pause button
		$('#slider a#play').click(function() {
			if(!$(this).hasClass('paused')) {
					$(this).addClass('paused');
					clearInterval(play);
					stopTimer();
				 }
			 else {
				 $(this).removeClass('paused');
				  animateTimer();
				  //start slider
				  rotateSwitch();
			 }
			});
			
		//video goster	
		$('#slider #panel a#video').click(function() {
				
				var video = $('#slider #thumbs li.selected div.video');
				$('#slider #preview').append(video.clone());
				
				//durdur
				clearInterval(play);
				stopTimer();
				resetTimer();
				$('#slider #preview .video').stop().fadeIn(1200);
				$('#slider a#video-close').stop().delay(1000).fadeIn(1200);
			});	
		
		//video kapat	
		$('#slider a#video-close').live('click', function() {
				
				$(this).stop().fadeOut();
				
				$('#slider #preview .video').stop().fadeOut(1000, function() {
					$(this).remove();
					animateTimer();
				  	//start slider
				  	rotateSwitch();
					});
				
				
			});	
	    
		
		
		//MAIN SLIDER	
		//***************************************************
		//***************************************************
		
		
		//************FIX v2
		//footer menu border fix
		$(function () {
			$('ul#footer-nav li:last').prev().removeClass('no-border');
		});
		//************FIX v2
		
	
	});// end doc load
	
	
	
	
	
	window.onload = function() {
			
			$('div#content div.caption img').fadeIn(1000);
			
		};//end window.onload	
		
		
		
		
		
		
		

		//MAIN SLIDER	FUNCTIONS
		//**********************************
		//**********************************
		function goToGallery(li) {
				
				//cleaning
				$('#slider #preview').empty();
				$('#slider #paging').empty();
				
				//generate slider-items and fill with images
				var $sliderItem;
				li.find('div.images div').each(function(i) {
					$sliderItem = $('<div class="slider-item"></div>');
					$sliderItem.append($(this).html());
					$('#slider #preview').append($sliderItem);
					$('#slider #paging').append('<a>' + (i+1) +'</a>');
					});
				
				
				//video button
				var video = li.find('.video');
				if(video.length) {
					
					//show video button
					$('#slider #panel a#video').fadeIn();
						
				}
				else {
					$('#slider #panel a#video').fadeOut();
				}
				
				//selected state
				li.siblings().removeClass('selected');
				li.addClass('selected');
				
				if(scroll) {
					//scroll to selected gallery
					scrollToGallery();
				}
				
				$("#paging a:first").addClass("active");
				//paging active i yeniden ayarla
				$active = $('#slider #paging a.active'); 
				goToSlide($("#slider div.slider-item:first"));
				
				//slider start emri
				clearInterval(play);
				//paused değilse timer ı oynat
				if(!$('#slider a#play').hasClass('paused')) {
					rotateSwitch();
				}
			}
		
		
		function goToSlide(div) {
				
				//diğerlerini gizle
				div.siblings('.slider-item').hide();
				
				//bunu göster
				div.fadeIn(800);
				
				//paused değilse timer ı oynat
				if(!$('#slider a#play').hasClass('paused')) {
					//timer animation
					stopTimer();
					resetTimer();
					animateTimer();
				}
			}
			
		 function animateTimer() {
			 	$('#slider #timer').animate({ width:634 }, slideTime, 'easeOutSine', function() {  } );
			 }	
		 function stopTimer() {
			 	$('#slider #timer').stop();
			 }
	     function resetTimer() {
				$('#slider #timer').width(0); 
		 }
		 
		 var scroll = true;
		 function scrollToGallery() {
			 	var index = $('#thumbs ul li.selected').index();
				$('#thumbs').stop().animate({ scrollTop:index*96 },1200,'easeOutExpo');	
		 }
		 
		
		//Paging  and Slider Function
		rotate = function(){
			 var div = $('#slider div.slider-item').eq($active.index());
		
			 $("#slider #paging a").removeClass('active'); //Remove all active class
			 $active.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)
		
			 //Slider Animation
			 goToSlide(div);
			 
			}; 
		var play = 	null;
		//Rotation  and Timing Event
		rotateSwitch = function(){
			 play = setInterval(function(){ //Set timer - this will repeat itself every x seconds
				  $active = $('#slider #paging a.active').next(); //Move to the next paging
				  if ( $active.length == 0) { //If paging reaches the end... - sona gelindiyse
				  		
						//temizle
						clearInterval(play);
						//bir sonraki galeriye git
						var nextGallery = $('#slider #thumbs li.selected').next();
					
						//sona gelindiyse ilk galeriye git
						if(nextGallery.length == 0) {
							goToGallery($('#slider #thumbs li:first'));
						} else {
							goToGallery(nextGallery);	
						}
						
						
				  }
				  rotate();
			 }, slideTime); //Timer speed in milliseconds
		};
		
		
		
		
		function makeScrollable(wrapper, scrollable){
		// Get jQuery elements
		var wrapper = $(wrapper), scrollable = $(scrollable);
		
		// Hide images until they are not loaded
		scrollable.hide();
		
		// Set function that will check if all images are loaded
		var interval = setInterval(function(){
			var images = scrollable.find('img');
			var completed = 0;
			
			// Counts number of images that are succesfully loaded
			images.each(function(){
				if (this.complete) completed++;	
			});
			
			if (completed == images.length){
				clearInterval(interval);
				// Timeout added to fix problem with Chrome
				setTimeout(function(){
					
					// Remove scrollbars	
					wrapper.css({overflow: 'hidden'});						
					
					scrollable.fadeIn(1000, function(){
						$('#slider #preview').removeClass('loading');
						//ilk galeriye git
		    			goToGallery($('#slider #thumbs li:first'));
						scrollThumb();	
					});					
				}, 200);	
			}
		}, 100);
		
		function scrollThumb(){			
			// height of area at the top at bottom, that don't respond to mousemove
			var inactiveMargin = 100;
			// Cache for performance
			var wrapperWidth = wrapper.width();
			var wrapperHeight = wrapper.height();
			// Using outer height to include padding too
			var scrollableHeight = scrollable.outerHeight() + 2*inactiveMargin;
			// Do not cache wrapperOffset, because it can change when user resizes window
			// We could use onresize event, but it's just not worth doing that 
			// var wrapperOffset = wrapper.offset();
			
			//When user move mouse over menu			
			wrapper.mousemove(function(e){
				
				var wrapperOffset = wrapper.offset();
				// Scroll menu
				var top = (e.pageY -  wrapperOffset.top) * (scrollableHeight - wrapperHeight) / wrapperHeight - inactiveMargin;	
				
				if (top < 0){
					top = 0;
				}
				wrapper.stop().animate({scrollTop:top},1000,'easeOutSine');
			});		
		}
	}
		
		
		//MAIN SLIDER	FUNCTIONS
		//**********************************
		//**********************************
		
		
		//************FIX v1
		//LOGOS	FUNCTIONS
		//**********************************
		
		//make logos scrollable on mouse move
		function makeLogosScrollable() {
				var div = $('div#logos'),
					ul = $('div#logos ul'),
					ulPadding = 20;
				
				var divWidth = div.width();
				div.css({overflow: 'hidden'});
				var lastLi = ul.find('li:last-child');
				
				div.mousemove(function(e){
					var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding;	
					var left = (e.pageX - div.offset().left) * (ulWidth-divWidth) / divWidth;
					div.stop().animate({ scrollLeft:left },500,'easeOutSine');
				});
			}
		
		
		 // logos auto play	
		 var playLogo = null;	
		 function playLogos() {	
		 	
			var div = $('div#logos'),
					ul = $('div#logos ul'),
					ulPadding = 20;
			var divWidth = div.width();
			
			var totalWidth =  0;
			$('div#logos ul li').each(function() {
				totalWidth += $(this).width();
				});
				
			// ul ye dinamik width hesapla	
			ul.width(totalWidth);
			
			var direction = 1;
			var posX = div.scrollLeft();
			var speed = 1;
				
		 	playLogo = setInterval(function(){
				
				posX = div.scrollLeft();
				
				if(posX >= totalWidth-divWidth+ulPadding*2) {
					direction = -1;	
				}
				else if (posX == 0) {
					direction = 1;
				}
				
				if(direction == 1) {
					$('div#logos').stop().animate({ scrollLeft : "+=" + speed },10);
				} else {
					$('div#logos').stop().animate({ scrollLeft : "-=" + speed },10);
					}
			},40);
		 }
		//LOGOS	FUNCTIONS
		//**********************************
		//************FIX v1

		
		
		
		
