
var isModernBrowser = document.createElement('canvas').getContext;

var slideTime = 4000, //main slider slide time
	productSlideTime = 3000;	//product slider slide time
var animSpeed = 800;
var activeSlide=0,
	play;

//******************* FONT REPLACEMENT
//********************************************************

//cufon ie8 performance fix...
var cufonHover = true;
if(!isModernBrowser) { cufonHover = false; }
//Cufon Font Replacement			
Cufon.replace('h2, h3, div.news p.date span' , { hover: cufonHover }); 

Cufon.replace('.nivo-caption h5, .bitki-wrapper h4' , { hover: cufonHover, fontFamily: 'PT Sans Bold' }); 

if(isModernBrowser) {
	
	//nav menu first-level links
	Cufon.replace('#nav a' , { hover: cufonHover });
	
	// service links
	Cufon.replace('.info h4' , { hover: cufonHover });	
}

Cufon.replace('.info h4' , { hover: cufonHover, textShadow: '0px 1px #ffffff)' });		
		
//******************* FONT REPLACEMENT
//********************************************************


$(function() {
		
		
		//**********************************
        //NAV MENU
		$('ul#nav li').each(function() { $(this).find('a').first().addClass('first'); $(this).append('<span class="mask"></span>'); });
		$('ul#nav ul li a').removeClass('first');
		
        $('ul#nav li').hover(function() {
 				
				if(isModernBrowser) {
 						$(this).find('.mask').stop(true,true).fadeIn(700);
					}else {
						$(this).find('.mask').stop(true,true).show();
					}
				
                var altMenu = $(this).find('div').length ? $(this).find('div') : $(this).find('ul:first');
 				
                //alt menüsü varsa
                if(altMenu.length) {
                    //linki seçili duruma getir
                    $(this).addClass('selected').find('a').eq(0).addClass("selected");
                    //alt menüsünü göster
                    altMenu.stop(true,true).slideDown(700,'easeOutBounce');
                }
            }, function() {  //hover out
 					
                    var altMenu = $(this).find('div').length ? $(this).find('div') : $(this).find('ul:first');
 					
					//alt menüsü varsa
                	if(altMenu.length) {
						//seçili durumdan çıkar
						$(this).removeClass("selected").find('a').eq(0).removeClass("selected");
						//alt menüsünü gizle
						altMenu.stop(true,true).delay(150).fadeOut(300);
					}
					
					if(isModernBrowser) {
							$(this).find('.mask').stop(true,true).delay(150).fadeOut(800);
						} else {
							$(this).find('.mask').stop(true,true).delay(150).hide();
						}
 
                });
        //NAV MENU
        //**********************************
		
	
	
		
		//**********************************
		// body - details
		if(!$('#slider').length) {
			$('body').addClass('details');
		}
		//**********************************
		
		
		//**********************************
		//NEWS ODD STYLING
		$('.news .newsItem:odd').addClass('odd');
		//**********************************
		
		
		//**********************************
		//PRESS STYLING
		var totalPress = $('.press .newsItem').length;
		$('.press .newsItem').each(function(i) {
			if((totalPress-i) <= 2 )
			 $(this).addClass('no-bg');
			});
		//**********************************
		
		
		
		//**********************************
		//TABLE STYLING
		$('table.styled tbody tr:odd').addClass('alt');
		//**********************************
		
		
		$('a#bitkiAns').hover(function() {
				$(this).stop().animate({ top:-15 },400,'easeOutCirc');
			}, function() {
				$(this).stop().animate({ top:-30 });
				});
				
		
		
		
		
		
		//**********************************
		//Bitki pagination
		if($("#ansWrapper").length) {
			$('#ansWrapper').pajinate({
						nav_label_first : '',
						nav_label_last : '',
						nav_label_prev : 'Geri',
						nav_label_next : 'İleri',
						items_per_page : 8
					});
		}
		//**********************************
		
		
		
		//update v1.1
		//*************************************
		//validation
		if($('.validateForm').length) {
			$('.validateForm').each(function() {
					$(this).validate();
				});
			
		}
		//*************************************
		//update v1.1
		
		
		
		
		
	}); //end doc.load	
	



// window.onload
//*******************************
window.onload = function() {
		
		
		var slideAni = isModernBrowser ? 'sliceUpDown' : 'fade';
		//MAIN SLIDER	
		//**********************************
		if($('#slider').length) {
			$('#slider').nivoSlider({
				effect:slideAni, // Specify sets like: 'fold,fade,sliceDown'
				slices:15, // For slice animations
				boxCols: 10, // For box animations
				boxRows: 5, // For box animations
				animSpeed:animSpeed, // Slide transition speed
				pauseTime:slideTime, // How long each slide will show
				startSlide:0, // Set starting Slide (0 index)
				directionNav:true, // Next & Prev navigation
				directionNavHide:false, // Only show on hover
				controlNav:false, // 1,2,3... navigation
				controlNavThumbs:false, // Use thumbnails for Control Nav
				keyboardNav:true, // Use left & right arrows
				pauseOnHover:true, // Stop animation while hovering
				manualAdvance:false, // Force manual transitions
				captionOpacity:1,
				prevText: '', // Prev directionNav text
				nextText: '',
				customChange: function(){ Cufon.refresh(); }
			});
		}
		//MAIN SLIDER	
		//**********************************
		
		//**********************************
		//news slider
		if($('div#news').length) {
				$('div#news .scrollable').scrollable({ vertical: false , circular: true, speed:600 }).autoscroll({ autoplay: true, interval:3000 });
			}
		//**********************************
		
		
		//**********************************
		//footer news slider
		if($('#footerNews').length) {
				$('#footerNews .scrollable').scrollable({ vertical: false , circular: false, speed:600, easing:'easeOutBack' }).navigator();
			}
		//**********************************
		
		
		//nav animation
		if($('#nav').length) { 
			if(isModernBrowser) {
				$('#nav').fadeIn(2000);
			} else {
				$('#nav').show();
			}
		}
		
		//bitki ans animation
		if($('a#bitkiAns').length) { $('a#bitkiAns').delay(600).animate({ top:-30 },1000,'easeOutBack'); }
		
		//home link animation
		if($('a#homeLink').length) { $('a#homeLink').delay(1200).fadeIn(1200); }
		
		
		//**********************************
		//logo animation
		if($('#logoWrap').length) { 
			$('#leaf').delay(300).slideDown(900,'easeOutExpo');
			$('#logo').fadeTo(1,0).delay(100).animate({ bottom:40,opacity:1 },1200,'easeOutExpo');
			$('#shine').delay(900).fadeToggle(1500);
		 }
		if(isModernBrowser) {
			setInterval(function() { $('#shine').fadeToggle(2000); $('#shine').fadeToggle(1200); },4000);
		}
		//**********************************
		
		
		//**********************************
		// UPDATE v1.2
		//**********************************
		
		
		//********************************** 
		//footer logo animation
		if($('#footerLogoWrap').length) { 
			if(isModernBrowser) { 
				$('#footerLogo').fadeTo(1,0).delay(100).animate({ bottom:40,opacity:1 },1200,'easeOutExpo');
				$('#footerShine').delay(900).fadeToggle(1500);
			} else {
				$('#footerLogo').show();
				}
		 }
		 if(isModernBrowser) {
			setInterval(function() { $('#footerShine').fadeToggle(2000); $('#footerShine').fadeToggle(1200); },6000);
		 }
		 //**********************************
		
		
		//**********************************
		//burs link animation
		if($('#bursLink').length) { 
			if(isModernBrowser) {
				$('#bursLink').delay(1600).fadeIn(1200);
			} else {
				$('#bursLink').delay(1600).show();
			}
		}
		$('#bursLink, #footerLogoWrap').hover(function() { 
				if(isModernBrowser)
					$(this).stop().fadeTo(500,.7); 
			}, function(){ 
				if(isModernBrowser)
					$(this).stop().fadeTo(400,1);
		});
		//**********************************
		
		
		//**********************************
		// UPDATE v1.2
		//**********************************
		
		
		
		//**********************************
		//caption animation
		if($('#caption').length) { $('#caption').delay(600).animate({ top:-165 },1200,'easeOutBack'); }
		//**********************************
		
		
		//**********************************
		//slider loading
		if($('#slider').length) { $('#slider').removeClass('loading'); }
		//**********************************
		
		
		//**********************************
		//content info - news animation
		$('.infos .info,.news .newsItem').each(function(i) {
			if(isModernBrowser) {
				$(this).delay(i*400+800).fadeIn(400);
			} else {
				$(this).delay(i*400+800).show();
			}
		});
		//**********************************
		
		
		//**********************************
		//lightbox
		if($('.lightbox').length) {  AcitvateLightbox(); }
		//**********************************
		
		
		};//end window.onload	
//*******************************		


// UPDATE v1.1
//*************************************
function AcitvateLightbox() {
	
		// Lightbox
		$("a.lightbox, .lightbox a").fancybox({
				'overlayColor'		: '#1f8625',
				'overlayOpacity'	: '0.9',
				'padding'			: '3',
				'margin'			: '80',
				'changeSpeed'		: '100',
				'transitionIn'		: 'elastic',
				'easingIn'			: 'easeOutBack',
				'speedIn'			: 600,
				'transitionOut'		: 'none',
				'hideOnOverlayClick': true,
				'centerOnScroll'	: true,
				'titlePosition' 	: 'over',
				'titleFormat'		: formatTitle,
				'onComplete' 		: function() {$("#fancybox-wrap").unbind('mousewheel.fb');}
			});
		//*************************************

	}
	
function formatTitle(title, currentArray, currentIndex, currentOpts) {
	var titleArray = title.split('-');
    return '<div class="fancyTitle">' + (title && title.length ? '' + titleArray[0] + '<span>'+ titleArray[1] + '</span>' : '' ) +  '</div>';
}
// UPDATE v1.1
//*************************************
