var rootUrl = "";

var timerB;
var directionB = "right";

function bannerlarOynat(){
	$('#navigation_'+directionB+'_button img').click();
}
/////////////////  BASLANGICTA YAP //////////////////////////
$(document).ready(function(){

ncl = parseInt($('#navigation_content').css('left'));

$('#navigation_left_button img').click(function(){
	if($('#navigation_content').queue("fx").length < 1){
	clearInterval(timerB);
	timerB = setInterval("bannerlarOynat()", 3000);
	ncl = parseInt($('#navigation_content').css('left')); 
	if ( ncl >= 0 ){  directionB = "right"; bannerlarOynat(); }
	else { 
		$('#navigation_content').stop().animate({left: ncl+250+'px'}, 1000); 
		//var ttt = $('div.anasayfa_capsul').eq(0).html();	
		//$('#navigation_content').append('<div id="'+$('div.anasayfa_capsul').eq(0).attr('id')+'" class="anasayfa_capsul">'+ttt+'</div>'); 
		//$('div.anasayfa_capsul').eq(0).remove();	
		}
		}
});
						   
$('#navigation_right_button img').click(function(){ 
	if($('#navigation_content').queue("fx").length < 1){
	clearInterval(timerB);
	 
	timerB = setInterval("bannerlarOynat()", 3000);
	ncl = parseInt($('#navigation_content').css('left'));
	if (ncl == -500 ){  directionB = "left"; bannerlarOynat(); }
	else {
		$('#navigation_content').stop().animate({left: ncl-250+'px'}, 1000);
		}
		}
});

timerB = setInterval("bannerlarOynat()", 3000);

$('.f1galeri a').lightBox();

if($('#defaultCountdown') != null)
{
    var newYear = new Date();
    //alert(newYear.setFullYear);
    //var curdate = "Sat, 24 May 2009 00:00:00 EST";
    newYear = new Date("March 14, 2010 15:00:00");
    //var newYear = new Date("Month dd, yyyy");
	    //newYear = new Date(newYear.getFullYear() + 1, 1 - 1, 1); 
	    $('#defaultCountdown').countdown({until: newYear});
}



$(".takvim li:nth-child(2n)").css("background-image","url(../../content/images/frontend/formula1_takvimbg2.png)");
$(".takvim li:first").css("margin-top","0");

$(".takvim li").each(function(i){
	$(this).children(".item").css("width",100/$(this).children(".item").size()+"%");	
});

$(".f1puan li:nth-child(2n) ul").css("background","#fff");
$(".f1puan li ul li:last-child").css("border-right","0").css("font-size","11px").css("font-weight","bold");
$(".f1puan li:last-child").css("border-bottom","1px solid #c4c4c4");


$(".mo").click(function()
{
    $("#logo").focus();
});

////////////////IE6 DETECT////////////
isExplorer6();
////////////////IE6 DETECT////////////

////////////MOUSE TAKIP ET////////////
$().mousemove(function(e){
		$(".icons_info").css({ top:e.pageY-130+"px", left:e.pageX-5+"px"});
		$("#bigimg").css({ top:e.pageY-140+"px", left:e.pageX-225+"px"});
});

$("#modelextra ul").hover(
	function (){
	$(".icons_info").show();
	},function(){
	$(".icons_info").hide();
});

$("#product_img").hover(
	function (){
	    if($("img", this).length > 0)
	    	$("#bigimg").show();
	},function(){
	    if($("img", this).length > 0)
	        $("#bigimg").hide();
});
////////////MOUSE TAKIP ET////////////

////////////sayfa içi class="mo" olan divleri bul ve div üstüne mouseover olunca içindeki img yi gizle falan filan ////////////////////// 
divs = document.getElementsByTagName('div');
for(i = 0; i < divs.length; i++){
		if (divs[i].className == 'mo'){
				var img = $(divs[i]).find('img').attr('src').split(rootUrl + "/content/images/frontend/").join("").split(".gif").join("").split(".jpg").join("");//////img.src yi al
				$(divs[i]).css({ cursor:"pointer",background: "url(" + rootUrl + "/content/images/frontend/"+img+"o.gif) no-repeat"});////////div'e backgroundimg at
				$(divs[i]).mouseover(function() {
						$(this).find('img').css({ visibility:"hidden"});//sakla
				}).mouseout(function(){
						$(this).find('img').css({ visibility:"visible"});//göster
				});
				//$(this).focus();
		}
}
////////////sayfa içi class="mo" olan divleri bul ve div üstüne mouseover olunca içindeki img yi gizle falan filan ////////////////////// 




///////////< menu>///////////////
$("#menubtns li ul").hide(); 
$("#menubtns li").hover(
	function () {
	$(this).children("img").css({ visibility:"hidden"});
	$(this).children("ul").show();
	},function(){
	$(this).children("img").css({ visibility:"visible"});
	$(this).children("ul").hide();
});

$("#menubtns li li").hover(
	function () {
	$(this).css({ backgroundColor:"#515151", color:"#ffffff"});
	$(this).children("a.extnavlink").css({ color:"#ffffff"});
	},function(){
	$(this).css({ backgroundColor:"#f7f7f7", color:"#2d2d2d"});
	$(this).children("a.extnavlink").css({ color:"#2d2d2d"});;
});
////////////</menu>///////////////

$("#newscontent").css({ visibility:"visible"});/////sayfa yüklenince haberleri goster

$(".bayi_detay").hide();/////sayfa yüklenince haberleri goster

///////////<left menu>///////////////
$('.selected').parent().parent().show();///////alt menüden seçiliyse sayfaya açik getir
$('.selected').parent().parent().parent().parent().show();

$("#leftmenu_items li").toggle(
    function () {
        if($(this).children("a").attr("href").indexOf('javascript') != 0 ) 
            window.location = $(this).children("a").attr("href");
        else 
            $(this).children("ul").show();
        },
    function () {
        $(this).children("ul").hide();
    }
);
///////////</left menu>///////////////


$("#zoom_btn").click(function(){$("#bigimg").show()});
$("#bigimg").click(function(){$(this).hide()});
$("#yorumyazbtn").click(function(){$("#yorum_formu").show();})
$("#comment").focus(function(){
    if ($.trim($(this).val()) == "Lütfen görüşlerinizi belirtiniz.")
    {
        $(this).val("");
        $(this).css("color", "#333333")
    }
})
///////////////////
$("#gonderbtn").click(function(){
//alert('lütfen yorum yapınız');

var star = $("input[name='yorum.star']:checked").val();

//var star = $("#yorum_formu input[@type=radio][@checked]").val();

var cBody = $("#comment").val();
var val = true;
if (typeof(star) == "undefined" || star == null)
{
    //showTT("yorum_formu", "Lütfen puan verin", "starTT", 10, 570, "tooltip");
    $("#comment_star_error").show();
    val = false;
}
else
{
    $("#comment_star_error").hide();
}

if (typeof(cBody) == "undefined" || cBody == null || $.trim(cBody) == "")
{
    //showTT("yorum_formu", "Lütfen yorum yazın", "commentTT", 60, 570, "tooltip");
    $("#comment").val("Lütfen görüşlerinizi belirtiniz.").css("color","#C0142C");
    val = false;
}
else if(typeof(cBody) != "undefined" && cBody != null && $.trim(cBody) == "Lütfen görüşlerinizi belirtiniz.")
{
    $("#comment").val("Lütfen görüşlerinizi belirtiniz.").css("color","#C0142C");
    val = false;
}

if(!val)
    return;
    
$("#starTT").remove();
$("#commentTT").remove();
    
$("#yorum_formu").hide();
$.ajax({
   type: "POST",
   url: rootUrl + "/urunler/yorumekle.aspx",
   data: "yorum.star="+star+"&yorum.body="+cBody+"&product.id="+$("#commentproductid").val(),
   success: function(msg){
	   $("#yorum_formu").show();
	   $("#yorumyazbtn").hide();
     $("#yorum_formu").html(msg);
   }
 });

})
////////////////////


$("#iletisim_formu input, textarea").focus(function () {
		$("#iletisim_formu input, textarea").css({background:"#f5f5f5", borderColor:"#a8a8a8"});
         $(this).css({background:"#eaebde", borderColor:"#afb197"});
    });


/////////////////////////////////
$("#transbg").click(function(){
		$(this).hide();
		$("#ajax_flvplayer").html("");
		$("#ajax_flvplayer").hide();
		$("#ajax_jingleplayer").html("");
		$("#ajax_jingleplayer").hide();
		$("#jingleplayer_downbtn").hide();
});
/////////////////////////////



$("#bayi_bulucu_sonuclar .cap").toggle(function()
{
	var id = this.id;
	$(".detail").hide();
	$(".mapDealer").hide();
	$("#detail" + id).show();
  $.ajax({
   type: "POST"
   ,
   url: "/hizmetlerimiz/bayidetay.aspx"
   ,
   data: "id=" + id
   ,
   success: function(msg)
   {
     $("#detail" + id).html(msg);
   }
 });
  
},function(){
	var id=this.id.substr(3);
	$("#detail"+id).hide();
	$(".map").hide();
	
});


$(".map").click(function(){$(this).hide();});

$("#searchbtn").click(function(){
    if ($.trim($("#searchinput").val()) != "")
        document.getElementById('searchform').submit();
});

$("#searchbtn2").click(function(){
    if ($.trim($("#searchinput2").val()) != "")
        document.getElementById('searchform2').submit();
});

$("#searchform").submit(function(){
    if ($.trim($("#searchinput").val()) == "")
        return false;
});

$("#searchform2").submit(function(){
    if ($.trim($("#searchinput2").val()) == "")
        return false;
});

var con = $("#content_txt").html();
if(con) con = con.split("<br><br><br><br>").join("");

//if(con.indexOf("basin_odasi_baslik") > -1) $("#content_txt").html(con);

});
/////////////////  BASLANGICTA YAP //////////////////////////


function krokiGoster(url)
{
    $("#google_map").show();
    $("#google_map").html("<img src='" + url + "' />");
    $(".close_map").show();
}

function closeMapButton()
{
    $("#google_map").hide();
    $("#google_map").html("");
    $(".close_map").hide();
}

////lastik seçici nin falan üstüne gelince bullet'i gizle//////////
function hide_arrow(this_,hide){
$(this_).css({ cursor:"pointer"});
if(hide==1) $(this_).find('img').css({ visibility:"hidden"});
else $(this_).find('img').css({ visibility:"visible"});
}

////lastik seçici nin falan üstüne gelince oku gizle//////////


////////////haberler-haberler-haberlerrrr//////////
var temptop=0;
var wait_time=5000;
var li_height=35;
var li_nums=4;
var top_limit=li_height*(li_nums-1);
window.direction = 1;
timer = setInterval(news_scroll,wait_time);

function news_scroll(){
		if(window.direction==1) temptop -=li_height; else temptop +=li_height;
		$("#newscontent").animate({top: temptop},"slow", function() {
				if(temptop<-top_limit) {
						temptop=0;
						$("#newscontent").css('top', temptop+li_height).animate({top: temptop},'slow');
				}
				if(temptop>0) {
						temptop=-top_limit;
						$("#newscontent").css('top', temptop-li_height).animate({top: temptop},'slow');
				}
				
		})
		window.clearInterval(timer);
		timer = setInterval(news_scroll,wait_time);
		window.direction=1;
}

function changenews(direction){
var top=parseInt(document.getElementById("newscontent").style.top);
if(!top) top=0;
if(top%li_height==0){
window.direction=direction;
window.clearInterval(timer);
timer = setInterval(news_scroll,1);
}
}
////////////haberler-haberler-haberlerrrr//////////


function url(url){
if(/^http.*/.exec(url) || /#/.exec(url) || url.substring(0,rootUrl.length) == rootUrl)
    window.location=url;
else
    window.location=rootUrl+url;
}
/////////////////
function open(){}
////////////////
function loadit(tab){
	$("#model_genel_mid1, #model_genel_mid2").hide();
	$("#model_genel a").removeClass();
	$(".link"+tab+" a").addClass("selected");
	$("#model_genel_mid"+tab).show();
	$("#model_genel_top").css({backgroundImage:"url(" + rootUrl + "/content/images/frontend/model_genel_bg1_"+tab+".gif)"});
}
///////////////////
function printpage() {
window.print();  
}
/////////////////


//////////////////
if(window.ActiveXObject){
ajax = new ActiveXObject("Microsoft.XMLHTTP");
}else if(window.XMLHttpRequest){
ajax = new XMLHttpRequest();
}

function showtvc(adi,dosya) {
window.down_url=dosya;
document.getElementById("transbg").style.display="block";
document.getElementById("ajax_flvplayer").style.display="block";
ajax.open('get', rootUrl + '/galeri/videoplayer.aspx?adi='+adi+'&dosya='+dosya , true);
ajax.onreadystatechange = showtvc_ok;
ajax.send(null);
}

function showtvc_ok(){
if(ajax.readyState==4){
	document.getElementById('ajax_flvplayer').innerHTML=ajax.responseText;
	isExplorer6();
}else{
	document.getElementById('ajax_flvplayer').innerHTML = "<div style='text-align:center;line-height:100px;color:#ffffff;'>Yukleniyor...</div>";}
}

function showjingle(adi,dosya) {
window.down_url=dosya;
document.getElementById("transbg").style.display="block";
document.getElementById("ajax_jingleplayer").style.display="block";
document.getElementById("jingleplayer_downbtn").style.display="block";
ajax.open('get', rootUrl + '/galeri/jingleplayer.aspx?adi='+adi+'&dosya='+dosya , true);
ajax.onreadystatechange = showjingle_ok;
ajax.send(null);
}

function showjingle_ok(){
if(ajax.readyState==4){
	document.getElementById('ajax_jingleplayer').innerHTML=ajax.responseText;
	isExplorer6();
}else{
	document.getElementById('ajax_jingleplayer').innerHTML = "<div style='text-align:center;line-height:100px;color:#ffffff;'>Yukleniyor...</div>";}
}

///////////////////



////////////////BUNLARA IE6 PNG TRANSPARENCY UYGULA////////////
function isExplorer6() {
	var appVer = navigator.appVersion;
	appVer = appVer.split(';');
	if(appVer[1] == ' MSIE 6.0') {
		$('#flvplayer').ifixpng();
		$('#jingleplayer').ifixpng();
		return true;
	}				
}
////////////////BUNLARA IE6 PNG TRANSPARENCY UYGULA////////////


/////////////////////////////////
$("#transbg").click(function(){
		$(this).hide();
		$("#ajax_flvplayer").html("");
		$("#ajax_flvplayer").hide();
		$("#ajax_jingleplayer").html("");
		$("#ajax_jingleplayer").hide();
		$("#jingleplayer_downbtn").hide();
});




function closeplayer(){
		document.getElementById("transbg").style.display="none";
		document.getElementById("ajax_flvplayer").innerHTML="";
		document.getElementById("ajax_flvplayer").style.display="none";
		document.getElementById("ajax_jingleplayer").innerHTML="";
		document.getElementById("ajax_jingleplayer").style.display="none";
		document.getElementById("jingleplayer_downbtn").style.display="none";
}



/////////////////////////////







///////
function map(id){
	$("#map"+id).show();
}
function mapDealer(id, dealerAppellation, delaerLatitude, delaerLongitude)
{
	
	
	map_mtop = Math.floor($("#map"+id).css("marginTop").split("px").join(""));
	map_mleft = Math.floor($("#map"+id).css("marginLeft").split("px").join(""));
	map_width = Math.floor($("#map"+id).css("width").split("px").join(""));
	
	btn_width = Math.floor($(".close_map2").css("width").split("px").join(""));
	btn_height = Math.floor($(".close_map2").css("height").split("px").join(""));
	
	$(".close_map2").css({marginTop : map_mtop-btn_height , marginLeft : map_mleft + (map_width - btn_width) + 4});
	
	$(".close_map2").click(function(){$(this).hide();$("#map"+id).hide();});
	
	
	
	

    $("#map"+id).show();
    $("#mapClose"+id).show();
    $("#map"+id).val( initialize("map" + id, dealerAppellation, delaerLatitude.substr(0, delaerLatitude.length - 2), delaerLongitude.substr(0, delaerLongitude.length - 2)) );
}
///////

function downloadjingle(){
	window.location.href= rootUrl + "/galeri/download.aspx?f=" + window.down_url;
}

function rateComment(obj, cid, r)
{
    if (typeof(cid) != "undefined" && cid != null && typeof(r) != "undefined" && r != null)
    {
        $.ajax({
            type: "POST",
            url: rootUrl + "/urunler/yorumdegerlendir.aspx",
            data: "cid="+cid+"&r="+r,
            success: function(msg){
               $("#yorumu_dogru_"+cid).html(msg);
               //showTT($(obj).attr("id"),msg, "ratetooltip" ,-35, 0,"tooltip");
            }
        });
    }
}

function logPage(obj, r)
{
    if (typeof(r) != "undefined" && r != null)
    {
        $.ajax({
            type: "POST",
            url: rootUrl + "/log/save.aspx",
            data: "logurl="+escape(window.location)+"&r="+r,
            success: function(msg){
               //showTT($(obj).attr("id"),msg, "logtooltip" ,-35, 0,"tooltip");
               $("#content_footer_txt").html("Görüşlerinizi paylaştığınız için teşekkür ederiz.");
               $("#content_footer_yes").remove();
               $("#content_footer_no").remove();
            }
        });
    }
}

$(function()
{
    $('.tyre .mask .content').jScrollPane({showArrows:true});    
    $(".jScrollPaneDrag").each(function(){
        var node = $(this).parent().parent().parent().parent();
        node.attr("style",node.attr("style")+";background:url(/content/images/frontend/tyres_bg.gif) no-repeat;");
    });
});

//////iLETiSiM FORMU VALIDATION/////////
function check_contact_form(){
                window.error=0;
                check_errors("konu",1,"normal");
                check_errors("ad",3,"normal");
                check_errors("soyad",3,"normal");
                
                
                if ($("#ev1").val().length < 3 || $("#ev2").val().length < 7)
	            {
	                if($("#cep1").val().length < 3 || $("#cep2").val().length < 7)
	                {
	                    alert('Lütfen telefon ve ya cep telefonu alanlarından birisini doldurunuz');
	                    check_errors("ev1",3,"numeric");
	                    check_errors("ev2",7,"numeric");
	                    //frm.PhoneCode.focus();
	                    //return false;
	                }
	                else
	                {
	                    $("#ev1").val("0");
	                    $("#ev2").val("0");
	                }
	            }
	            else
	            {
	                check_errors("ev1",3,"numeric");
	                check_errors("ev2",7,"numeric");
	                $("#cep1").val("0");
	                $("#cep2").val("0");
	            }
                
                
                /*
                check_errors("ev1",3,"numeric");
                check_errors("ev2",7,"numeric");
                check_errors("cep1",3,"numeric");
                check_errors("cep2",7,"numeric");
                */
                
                check_errors("email",5,"email");
                check_errors("il",1,"normal");
                check_errors("ilce",1,"normal");
                check_errors("mesaj",15,"normal");
                if(window.error==1) return false;
}
//////iLETiSiM FORMU VALIDATION/////////


////////// HATALI ALANLAR/////////////
function check_errors(field,charlength,check_type){
                               if(check_type=="numeric") q=$("#"+field).val().length<charlength || isNaN($("#"+field).val());
                               else if(check_type=="email") q=$("#"+field).val().length<charlength || $("#"+field).val().indexOf("@")<1 || ($("#"+field).val().indexOf("@")+2)>$("#"+field).val().lastIndexOf(".") || $("#"+field).val().lastIndexOf(".")>($("#"+field).val().length-2);
                               else q=$("#"+field).val().length<charlength;
                               if(q){
                                                               $("#"+field).removeClass("field_ok");
                                                               $("#"+field).addClass("field_error");
                                                               $(".warnings ."+field).show();
                                                               if(window.error==0) $("#"+field).focus();
                                                               window.error=1;
                               }else{
                                                               $("#"+field).removeClass("field_error");
                                                               $("#"+field).addClass("field_ok");
                                                               $(".warnings ."+field).hide();
                               }
}
////////// HATALI ALANLAR/////////////




////// Kampanyalardan Haberdar Et //////

function Temizle()
{
	if ($("#kampanya").val()=="E-posta Adresi")
	{
		$("#kampanya").val("");
	}
}

function kampanyalardanhaberdaret()
{
        
		var email = $("#kampanya").val();
		
		if (!emailCheck(email))
		{
			alert('Lütfen gecerli bir eposta adresi giriniz');
			return false;
		}
		
		$.ajax({
            type: "GET",
            url: "haberdarolmakistiyorum.asp",
            data: "email="+email,
            success: function(msg){
               
               if (msg=="true")
			   {
					alert("Kaydiniz alinmistir, ilginiz icin tesekkur ederiz.");
			   }else if (msg=="false")
			   {
					alert("isteginiz zaman asimina ugramistir.");
			   }else if (msg=="mailvar")
			   {   
				   alert("Mailiniz kayitli gorunuyor ilginiz icin tesekkurler.");
			   }
            }
        });
}



function emailCheck (emailStr) {
		var emailPat=/^(.+)@(.+)$/
		var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
		var validChars="\[^\\s" + specialChars + "\]"
		var quotedUser="(\"[^\"]*\")"
		var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
		var atom=validChars + '+'
		var word="(" + atom + "|" + quotedUser + ")"
		var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
		var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")

		var matchArray=emailStr.match(emailPat)
			if (matchArray==null) {
				return false
			}

		var user=matchArray[1]
		var domain=matchArray[2]

		if (user.match(userPat)==null) {
			return false
		}

		var IPArray=domain.match(ipDomainPat)
			if (IPArray!=null) {
				for (var i=1;i<=4;i++) {
					if (IPArray[i]>255) {
						return false
					}
				}
				return true
			}

		var domainArray=domain.match(domainPat)
		if (domainArray==null) {
			return false
		}

		var atomPat=new RegExp(atom,"g")
		var domArr=domain.match(atomPat)
		var len=domArr.length
		
		if (domArr[domArr.length-1].length<2 || 
			domArr[domArr.length-1].length>3) {
			return false
		}

		if (len<2) {
			return false
		}

		return true;
}




////// Kampanyalardan Haberdar Et //////