$(document).ready(function(){
    var slideNo=1;
	$('.corporateFiles a.last, .onlineService a.sifreli').click(function(e) {
		var password = prompt(lang['pleaseEnterPassword'], '');
		if( password != null && password != '' && password == 'elvin123456') {
			return true;
		} else if( password == null || password == '') {
			alert(lang['mustFillPasswordField']);
			e.preventDefault();
			return false;
		} else {
			alert(lang['wrongPassword']);
			e.preventDefault();
			return false;
		}
		e.preventDefault();
		return false;
	});
	
	// Home Slider
	function changeSlider() {
		slideNo++;	
		var $activeSliderImage = $('.banner .images .sliderImage.active');
		var $activeCaption = $('.banner .images .caption.displayBlock');
		var $activeControl = $('.banner .timer-bar li.active');
		var $activeControl2 = $('.banner .timer-bar li.active2');
		
		$activeSliderImage.fadeOut('slow').removeClass('active');
		if($activeSliderImage.is($('.banner .images .sliderImage').last())) {
			$('.banner .images .sliderImage:first').fadeIn('slow').addClass('active');
		} else {
		    $activeSliderImage.next().fadeIn('slow').addClass('active');
		}
		
		$activeCaption.fadeOut('slow').removeClass('displayBlock');
		if($activeCaption.is($('.banner .images .caption').last())) {
			$('.banner .images .caption:first').fadeIn('slow').addClass('displayBlock');
			slideNo=1;
			setTimeout(changeSlider, 5000);
		} else {
		    $activeCaption.next().fadeIn('slow', function() {										
			setTimeout(changeSlider, 5000);
			}).addClass('displayBlock');
		}
		
		//alert(slideNo);
		if (slideNo==1){
		$activeControl2.removeClass('active2');
		$('.banner .timer-bar li:first').addClass('active');
		} else {
		$activeControl.removeClass('active');
		}
		$activeControl.removeClass('active');
		if($activeControl.is($('.banner .timer-bar li:not(.rotate)').last())) {
			$('.banner .timer-bar li:first').addClass('active');
		} else {
			if(slideNo==6){
			$activeControl.next().addClass('active2');
			} else {
			$activeControl.next().addClass('active');
			}
			
			
		}
		
	}
	setTimeout(changeSlider, 5000);
    
	// Sub Page Gallery
	$(".gallery .galleryMainImage ul li:first").addClass('active');
	$(".gallery .galleryThumbnailImage ul li:first").addClass('active');
	function changeGallery($gallery, index) {
		$img = $gallery.find('.galleryMainImage ul li:nth-child(' + index + ') > img');
		$img.attr('src', $img.attr('rel'));
		$gallery.find('.galleryThumbnailImage ul li.active').removeClass('active');
		$gallery.find('.galleryThumbnailImage ul li:nth-child(' + index + ')').addClass('active');
		$gallery.find('.galleryMainImage ul li.active').fadeOut().removeClass('active');
		$gallery.find('.galleryMainImage ul li:nth-child(' + index + ')').fadeIn().addClass('active');
	}
	$(".gallery .galleryThumbnailImage ul li").click(function(e) {
		if(!$(this).hasClass("active")) {
			changeGallery($(this).parent().parent().parent(), $(this).index() + 1);
		}
		e.preventDefault();
	});
	// set up galleryWithSpot height
	var galleryHeight = 0;
	$(".gallery .galleryMainImage ul li").each(function() {
		var $firstSpan = $(this).find('span').first();
		if($firstSpan.length == 1) {
			galleryHeight = ($firstSpan.height() > galleryHeight ? $firstSpan.height() : galleryHeight);
		}
	});
	$(".gallery .galleryMainImage ul li").each(function() {
		$(this).find('span').first().css('height', galleryHeight);
	});
	$(".gallery .galleryMainImage").css('height', galleryHeight + $(".gallery .galleryMainImage").height());
	
	// news hub page
	$(".newsList dl dt").hoverIntent(function(e) {
		$(this).next('dd').show();
	}, function() {});
	$(".newsList dl dd").mouseout(function(e) {
		$(this).hide();
	});
	
	
	
	$('ul.sf-menu').superfish();
	$('.slider').bxSlider();
	
	
	
    // Bayiler
	$('#searchForm select').live('change', function(e) {
		$('#searchForm').load($(':selected', this).val() + ' #searchForm > *');
		$('#searchResult').load($(':selected', this).val() + ' #searchResult > *', function() {
			$('html, body').animate({ scrollTop: $('#searchForm').offset().top }, 'slow');
		});
	});
	$('.pages a').live('click', function(e) {
	    $('#searchResult').load($(this).attr('href') + ' #searchResult > *', function() {
			$('html, body').animate({ scrollTop: $('#searchForm').offset().top }, 'slow');
		});
		e.preventDefault();
	});
	
	$('.goBack').click(function() {
		history.go(-1);
	});
});
