var Lkucuk = {width:172, 'margin-top':80, 'margin-left':4};
var Lbuyuk = {width:322, 'margin-top':0, 'margin-left':4};
var Ikucuk = {width:140};
var Ibuyuk = {width:300};
var n;
var navH='';
var tas;
var tasiyici;
$(function(){
	$.mask.definitions['~']='[0-5]';
    $.mask.definitions['^']='[0-2]';
    $.mask.definitions['`']='[2-5]';
    $('input[name=saat]').mask('^9:~9');
    $('input.tel').mask('0(`99) 999 99 99');
    $('#telefon').mask('0(`99)9999999');
	/*+++++++++++ Menu ++++++++++++*/
	$('#menu ul li').has('ul').addClass('hasul');
	$('li.hasul').bind('mouseenter',function(){
		n=$('ul:first',this);
		if (navH=='') navH = n.height();
		n.css({display:'block',height:'0px'});

		n.stop().animate({

			height:navH,

			queue:false

		},500,function(){

			n.css({height:'auto'});

			navH = n.height();

		});

	}).bind('mouseleave',function(){

		n.stop().animate({

			height:0,

			queue:false

		},500,function(){

			n.css({display:'none'});

		});

	});
	/* ------------- Menu --------------*/
	
	/* +++++++++++++ Slider ++++++++++++*/
	$('ul').each(function(i){
        $('li:first',this).addClass('ilk');$('li:last',this).addClass('son');
    });
	var animationComplete=false;
	$('#slider .next').live('click',function(){
		if (animationComplete){
			animationComplete=false;
			$('#slider .tasiyici').jcarousel('next');
		}
	});
	$('#slider .prev').live('click',function(){
		if (animationComplete){
			animationComplete=false;
			$('#slider .tasiyici').jcarousel('prev');
		}
	});
	
	$('#slider .tasiyici').jcarousel({
		wrap: 'circular',
		scroll:1,
		visible:5,
        animation: 1000,
		auto:($('#slider .tasiyici li').length>5)?2:0,
		itemFallbackDimension:172,
		initCallback:function(carousel,state){
			if (state=='init' || state=='reset'){
				$('.yan').css(Lkucuk);
				$('.orta').css(Lbuyuk);
			}
			$('.ortabaslik').fadeOut(800).text($('.jcarousel-item:nth(2)').children('h3').text()).fadeIn(200);
			$('.tikla a').attr('href',$('.jcarousel-item:nth(2)').children('h3 a').attr('href'));
		},
		itemVisibleOutCallback:{
			onBeforeAnimation: function(c,li,i,d){
				if (d=='next'){
					var orta = $(li).next().next();
					var sonraki =orta.next();
				}else{
					var orta = $(li).prev().prev();
					var sonraki = orta.prev();
				}
				orta.animate(Lkucuk).find('img').animate(Ikucuk,function(){
				  orta.siblings().css(Lkucuk);
				});
				$('.tikla a').attr('href',$('h3 a',sonraki).attr('href'));
                //alert($('h3 a',sonraki).attr('href'));
				$('.ortabaslik').fadeOut(800,function(){
					$(this).text($(sonraki).children('h3').text()).fadeIn(200);
				});
				sonraki.animate(Lbuyuk,function(){
					$(this).find('img').animate(Ibuyuk,function(){
						animationComplete=true;
					});
				});
			},
			onAfterAnimation:function(c,li,i,d){
                $('#slider .tasiyici li').removeClass('orta').addClass('yan');
				 $('#slider .tasiyici li[jcarouselindex='+(Number(c.first)+2)+']').removeClass('yan').addClass('orta');
			}
		}
	});
	/* ------------ Slider ------------- */
	if ($("#habertasiyici").length>0) ticker_start();
	if ($('#pizzalar').length>0){
		$('#pizzalar').cycle({
			fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
			//pager:'#pager',
			prev:'.box.son .prev', 
			next:'.box.son .next'
		});
	}
	if ($('#kampanyalar').length>0){
		$('#kampanyalar').cycle({
			fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
			//pager:'#pager',
			prev:'.box .kamprev', 
			next:'.box .kamnext'
		});
	}
	$("#loading").ajaxStart(function(){
		$('#loading_bg').after('<img src="'+mediaurl+'icons/loading.gif" class="loading"/>');
	   $(this).show();
	}).ajaxComplete(function(){
		$('img.loading',this).remove();
	});
	$(window).bind('resize',function(){
		$('.yan').css(Lkucuk);
        $('.orta').css(Lbuyuk);
	});
	$('form').validationEngine();
    
    $('.tooltip').tooltip({
        /*bodyHandler: function() {
            var a=$(this).attr('alt');
            //alert(a);
            return a;
        }, */
        showURL: false,
        track: true, 
        delay: 0, 
        showBody: " - ", 
        fade: 250
    });
    $('a[rel=lightbox],a[rel=fancybox],a.fancybox').fancybox({type:$(this).attr('type')});
    
    $('#telefon').each(function(){
        $(this).keydown(function(event){
            if ((event.keyCode>47 && event.keyCode<58) || (event.keyCode>95 && event.keyCode<106) || event.keyCode==8 || event.keyCode==13 || event.keyCode==46 || (event.keyCode>36 && event.keyCode<41) || event.keyCode==9)
                return true;
            else
                return false;
        })
    });
});

function ticker_start() {
	tasiyici=$("#habertasiyici");
	tas=document.getElementById('habertasiyici');
	TICKER_RIGHTTOLEFT = false;
	TICKER_SPEED = 2;
	TICKER_STYLE = "font-family:Arial; font-size:12px; color:#444444";
	TICKER_PAUSED = false;
	TICKER_CONTENT = tasiyici.html();
	var tickerSupported = false;
	TICKER_WIDTH = tasiyici.css('width');
	
	var img = "<img src=ticker_space.gif width="+TICKER_WIDTH+" height=0>";

	// Firefox
		tas.innerHTML = "<TABLE  cellspacing='0' cellpadding='0' width='100%'><TR><TD nowrap='nowrap'>"+img+"<SPAN style='"+TICKER_STYLE+"' ID='TICKER_BODY' width='100%'>&nbsp;</SPAN>"+img+"</TD></TR></TABLE>";
		tickerSupported = true;
	// IE
	
	if(!tickerSupported) tas.outerHTML = ""; else {
		tas.scrollLeft = TICKER_RIGHTTOLEFT ? tas.scrollWidth - tas.offsetWidth : 0;
		document.getElementById("TICKER_BODY").innerHTML = TICKER_CONTENT;
		tas.style.display="block";
		TICKER_tick();
	}
}

function TICKER_tick() {
	if(!TICKER_PAUSED) tas.scrollLeft += TICKER_SPEED * (TICKER_RIGHTTOLEFT ? -1 : 1);
	if(TICKER_RIGHTTOLEFT && tas.scrollLeft <= 0) tas.scrollLeft = tas.scrollWidth - tas.offsetWidth;
	if(!TICKER_RIGHTTOLEFT && tas.scrollLeft >= tas.scrollWidth - tas.offsetWidth) tas.scrollLeft = 0;
	window.setTimeout("TICKER_tick()", 30);
}

function addslashes(str) {
    str=str.replace(/\\/g,'\\\\');
    str=str.replace(/\'/g,'\\\'');
    str=str.replace(/\"/g,'\\"');
    str=str.replace(/\0/g,'\\0');
    return str;
}
function stripslashes(str) {
    str=str.replace(/\\'/g,'\'');
    str=str.replace(/\\"/g,'"');
    str=str.replace(/\\0/g,'\0');
    str=str.replace(/\\\\/g,'\\');
    return str;
}

function str_replace (search, replace, subject, count) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Gabriel Paderni
    // +   improved by: Philip Peterson
    // +   improved by: Simon Willison (http://simonwillison.net)
    // +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +   bugfixed by: Anton Ongson
    // +      input by: Onno Marsman
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +    tweaked by: Onno Marsman
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   input by: Oleg Eremeev
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Oleg Eremeev
    // %          note 1: The count parameter must be passed as a string in order
    // %          note 1:  to find a global variable in which the result will be given
    // *     example 1: str_replace(' ', '.', 'Kevin van Zonneveld');
    // *     returns 1: 'Kevin.van.Zonneveld'
    // *     example 2: str_replace(['{name}', 'l'], ['hello', 'm'], '{name}, lars');
    // *     returns 2: 'hemmo, mars'
    var i = 0,
        j = 0,
        temp = '',
        repl = '',
        sl = 0,
        fl = 0,
        f = [].concat(search),
        r = [].concat(replace),
        s = subject,
        ra = Object.prototype.toString.call(r) === '[object Array]',
        sa = Object.prototype.toString.call(s) === '[object Array]';
    s = [].concat(s);
    if (count) {
        this.window[count] = 0;
    }

    for (i = 0, sl = s.length; i < sl; i++) {
        if (s[i] === '') {
            continue;
        }
        for (j = 0, fl = f.length; j < fl; j++) {
            temp = s[i] + '';
            repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
            s[i] = (temp).split(f[j]).join(repl);
            if (count && s[i] !== temp) {
                this.window[count] += (temp.length - s[i].length) / f[j].length;
            }
        }
    }
    return sa ? s : s[0];
}
