﻿

var setMenuTimeoutset = null;
var elm;

function onlyLetter(e) {
    var InvalidChars = "!#/*{[()]},;%^><\\?+:='`|0123456789";
    var keyCode = ($.browser.mozilla) ? e.which : event.keyCode;
    if (keyCode > 47 && keyCode < 58) {
        return false;
    }
    for (i = 0; i <= InvalidChars.length - 1; i++) {
        if (keyCode == InvalidChars.charCodeAt(i)) {
            return false;
        }
	}
}

	
// Go to URL
function DoNav(theUrl)
{
 	document.location.href = theUrl;
}

$().ready(function(){
	$(".hasSub img").each(function() {
		$(this).attr("change", $(this).attr("src").split(".jpg")[0])
	})
	
	$("li.sublink").hover(function() {
		$(this).find(".hasSub img").attr("src", $(this).find(".hasSub img").attr("change") + "-on.jpg");
		$(this).find(".subMenu").show();
		var offs = $(this).offset();
		$(this).find(".subMenu").children('.subMenuContent').css({
			width: ($(window).width() - offs.left) - 18 + "px"
		});
	}, function() {
	$(this).find(".hasSub img").attr("src", $(this).find(".hasSub img").attr("change") + ".jpg");
		$(this).find(".subMenu").hide();
	})
	
	$(".worksFrame").hover(function() {
		var thumbOver = $(this).find("img").attr("src");
		$(this).find("a.thumb").css({'background' : 'url(' + thumbOver + ') no-repeat center bottom'});
		$(this).find("span").stop().fadeTo('normal', 0 , function() {
			$(this).hide()
		});
	} , function() { 
		$(this).find("span").stop().fadeTo('normal', 1).show();
	});
	$(".worksFrame3").hover(function() {
		var thumbOver = $(this).find("img").attr("src");
		$(this).find("a.thumb").css({'background' : 'url(' + thumbOver + ') no-repeat center bottom'});
		$(this).find("span").stop().fadeTo('normal', 0 , function() {
			$(this).hide()
		});
	} , function() { 
		$(this).find("span").stop().fadeTo('normal', 1).show();
	});	
	
	
	// Home Page Mykea Slide
$(".design_thumb").live("click",function(){window.location.href=$(this).find("a").attr("href");return false});$(".design_thumb .stripe").live("mouseover",function(){var stripe=$(this).attr("class").split(" ");var el=$(this).parents(".design_thumb").find(".overlays ."+stripe[1]).show()});$(".design_thumb .stripe").live("mouseout",function(){var stripe=$(this).attr("class").split(" ");$(this).parents(".design_thumb").find(".overlays ."+stripe[1]).hide(0)})
	
	
	
	// Tabs
	$(".tab_content").hide();
	$("ul.tabs li:first-child").addClass("active").show();
	$(".block").find(".tab_content:first").show();

	$("ul.tabs li").click(function() {
		$(this).parent().find('li').removeClass("active");
		$(this).addClass("active");
		$(this).parents('.block').find(".tab_content").hide();

		var activeTab = $(this).find("a").attr("href");
		$(activeTab).show();
		return false;
	});	
	// Sidebar Tabs
	$(".sidebar_content").hide();
	
	if(window.location.hash && window.location.hash.match('sb')) {
	
		$("ul.sidemenu li a[href="+window.location.hash+"]").parent().addClass("active").show();
		$(".block .sidebar_content#"+window.location.hash).show();
	} else {
	
		$("ul.sidemenu li:first-child").addClass("active").show();
		$(".block .sidebar_content:first").show();
	}

	$("ul.sidemenu li").click(function() {
	
		var activeTab = $(this).find("a").attr("href");
		window.location.hash = activeTab;
	
		$(this).parent().find('li').removeClass("active");
		$(this).addClass("active");
		$(this).parents('.block').find(".sidebar_content").hide();			
		$(activeTab).show();
		return false;
	});	
	
	// Sub menu footer
	$('#subMenuOpen').hover(function(event) {
	$('#subMenuFooter').toggle("400");
	});

	// Maillist
		$('#bultenKaydet').submit(function () {		
		
		var mail_adresi = $('input[name=mail_adresi]');

		if (mail_adresi.val().length<5) {
			alert('Lütfen eposta adresinizi kontrol edin.');
			mail_adresi.focus();
			mail_adresi.addClass('hightlight');
			return false;
		} else mail_adresi.removeClass('hightlight');
		
		var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
		if (!filter.test(mail_adresi.val())) {
			alert('Lütfen eposta adresinizi kontrol edin.');
			mail_adresi.focus();
			mail_adresi.addClass('hightlight');
			return false;
		} else mail_adresi.removeClass('hightlight');
		
		var Bultendata = 'mail_adresi=' + mail_adresi.val();
				
		$('.loadingMaillist').show();
		
		//start the ajax
		$.ajax({
			url: "mailkaydet.php",	
			
			type: "GET",

			data: Bultendata,		
			
			cache: false,
			
			//success
			success: function (html) {				
				if (html==1) {					
					//hide the form
					$('.Bultenform').fadeOut('slow');		
					$('.BultenUyari').fadeOut('slow');		
					
					//show the success message
					$('.Bultendone').fadeIn('slow');
					
				} else if(htlm==0) {
				
				$('.BultenUyari').show();
				}
			}		
		});
		
		return false;
	});
	
	$('#bultenKaydetTrigger').click(function () {		
		
		var mail_adresi = $('input[name=mail_adresi]');

		if (mail_adresi.val().length<5) {
			alert('Lütfen eposta adresinizi kontrol edin.');
			mail_adresi.focus();
			mail_adresi.addClass('hightlight');
			return false;
		} else mail_adresi.removeClass('hightlight');
		
		var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
		if (!filter.test(mail_adresi.val())) {
			alert('Lütfen eposta adresinizi kontrol edin.');
			mail_adresi.focus();
			mail_adresi.addClass('hightlight');
			return false;
		} else mail_adresi.removeClass('hightlight');
		
		var Bultendata = 'mail_adresi=' + mail_adresi.val();
				
		$('.loadingMaillist').show();
		
		//start the ajax
		$.ajax({
			url: "mailkaydet.php",	
			
			type: "GET",

			data: Bultendata,		
			
			cache: false,
			
			//success
			success: function (html) {				
				if (html==1) {					
					//hide the form
					$('.Bultenform').fadeOut('slow');		
					$('.BultenUyari').fadeOut('slow');		
					
					//show the success message
					$('.Bultendone').fadeIn('slow');
					
				} else if(htlm==0) {
				
				$('.BultenUyari').show();
				}
			}		
		});
		
		return false;
	});	
	
	
	// Contact Form
	 	$('#submit').click(function () {		
		
		var fName = $('input[name=fName]');
		var fEmail = $('input[name=fEmail]');
		var fPhone = $('input[name=fPhone]');
		var fMessage = $('textarea[name=fMessage]');
		
		if (fName.val().length<3 || fName.val() == 'Name and Surname') {
			fName.focus();
			$('#fNameErr').fadeIn("100");
			return false;
		} else $('#fNameErr').fadeOut("100");
		
		var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
		if (!filter.test(fEmail.val()) || fEmail.val() == 'example@example.com') {
			fEmail.focus();
			$('#fEmailErr').fadeIn("100");
			return false;
		} else $('#fEmailErr').fadeOut("100");
		
		if (fMessage.val().length<3 || fMessage.val() == 'Your message') {
			fMessage.focus();
			$('#fMessageErr').fadeIn("100");
			return false;
		} else $('#fMessageErr').fadeOut("100");
		
		var data = 'adsoyad=' + fName.val() + '&telefon=' + fPhone.val() + '&eposta='
		+ fEmail.val() + '&yorum='  + encodeURIComponent(fMessage.val());
		
		$('.inputC').attr('disabled','true');
		$('.textareaC').attr('disabled','true');
		
		$('.loading').show();
		
		//start the ajax
		$.ajax({
			url: "email.php",	
			
			type: "GET",

			data: data,		
			
			cache: false,
			
			//success
			success: function (html) {				
				if (html==1) {					
					//hide the form
					$('.form').fadeOut('slow');					
					
					//show the success message
					$('.done').fadeIn('slow');
					
				} else alert('Please fill the form to contact us.');				
			}		
		});
		
		return false;
	});
	

})

   /**
   * jQuery.Preload
   * Copyright (c) 2008 Ariel Flesler - aflesler(at)gmail(dot)com
   * Dual licensed under MIT and GPL.
   * Date: 3/12/2008
   *
   * @projectDescription Multifunctional preloader
   * @author Ariel Flesler
   * @version 1.0.7
   */
   ; (function($) {

   	var $preload = $.preload = function(original, settings) {
   		if (original.split)//selector
   			original = $(original);

   		settings = $.extend({}, $preload.defaults, settings);
   		var sources = $.map(original, function(source) {
   			if (!source)
   				return; //skip
   			if (source.split)//URL Mode
   				return settings.base + source + settings.ext;
   			var url = source.src || source.href; //save the original source
   			if (typeof settings.placeholder == 'string' && source.src)//Placeholder Mode, if it's an image, set it.
   				source.src = settings.placeholder;
   			if (url && settings.find)//Rollover mode
   				url = url.replace(settings.find, settings.replace);
   			return url || null; //skip if empty string
   		});

   		var data = {
   			loaded: 0, //how many were loaded successfully
   			failed: 0, //how many urls failed
   			next: 0, //which one's the next image to load (index)
   			done: 0, //how many urls were tried
   			//found:false,//whether the last one was successful
   			total: sources.length//how many images are being preloaded overall
   		};

   		if (!data.total)//nothing to preload
   			return finish();

   		var imgs = '<img/>', //ensure one
			thres = settings.threshold; //save a copy

   		while (--thres > 0)//it could be oddly negative
   			imgs += '<img/>';
   		imgs = $(imgs).load(handler).error(handler).bind('abort', handler).each(fetch);

   		function handler(e) {
   			data.found = e.type == 'load';
   			data.image = this.src;
   			var orig = data.original = original[this.index];
   			data[data.found ? 'loaded' : 'failed']++;
   			data.done++;
   			if (settings.placeholder && orig.src)//special case when on placeholder mode
   				orig.src = data.found ? data.image : settings.notFound || orig.src;
   			if (settings.onComplete)
   				settings.onComplete(data);
   			if (data.done < data.total)//let's continue
   				fetch(0, this);
   			else {//we are finished
   				if (imgs.unbind)//sometimes IE gets here before finishing line 84
   					imgs.unbind('load').unbind('error').unbind('abort'); //cleanup
   				imgs = null;
   				finish();
   			}
   		};
   		function fetch(i, img, retry) {
   			if ($.browser.msie && data.next && data.next % $preload.gap == 0 && !retry) {//IE problem, can't preload more than 15
   				setTimeout(function() { fetch(i, img, true); }, 0);
   				return false;
   			}
   			if (data.next == data.total) return false; //no more to fetch
   			img.index = data.next; //save it, we'll need it.
   			img.src = sources[data.next++];
   			if (settings.onRequest) {
   				data.image = img.src;
   				data.original = original[data.next - 1];
   				settings.onRequest(data);
   			}
   		};
   		function finish() {
   			if (settings.onFinish)
   				settings.onFinish(data);
   		};
   	};

   	// each time we load this amount and it's IE, we must rest for a while, make it lower if you get stack overflow.
   	$preload.gap = 14;

   	$preload.defaults = {
   		threshold: 2, //how many images to load simultaneously
   		base: '', //URL mode: a base url can be specified, it is prepended to all string urls
   		ext: '', //URL mode:same as base, but it's appended after the original url.
   		replace: ''//Rollover mode: replacement (can be left empty)
   		/*
   		find:null,//Rollover mode: a string or regex for the replacement
   		notFound:''//Placeholder Mode: Optional url of an image to use when the original wasn't found
   		placeholder:'',//Placeholder Mode: url of an image to set while loading
   		onRequest:function( data ){ ... },//callback called every time a new url is requested
   		onComplete:function( data ){ ... },//callback called every time a response is received(successful or not)
   		onFinish:function( data ){ ... }//callback called after all the images were loaded(or failed)
   		*/
   	};

   	$.fn.preload = function(settings) {
   		$preload(this, settings);
   		return this;
   	};

   })(jQuery);
