// JavaScript Document

$(document).ready(function() {
	if ($("#logo").length > 0) { 
		$("#logo").click(function(event) { window.location = "default.asp"; }).addClass('hand');
	}
	if ($(".basadon").length > 0) $(".basadon").click(function(event) { 
															   if ($.browser.opera) $('html').animate({scrollTop:0}, 200);
															   else $('html, body').animate({scrollTop:0}, 200); 
															}).addClass('hand');
	$(window).resize(function() { yukseklikAyarla() });
	yukseklikAyarla();
	
	if ($("a.fancy").length > 0) {
		$("a.fancy").fancybox({
			frameWidth: 640,
			frameHeight: 655,
			hideOnContentClick: false,
			centerOnScroll: false
		});
	}
	
});

/*

	***	Anchor Slider by Cedric Dugas   ***
	*** http://www.position-absolute.com ***
	*** Hazar Karabay tarafından modifiye edildi ***
	
*/
$(document).ready(function() {
	$("a.anchorLink").anchorAnimate()
});

var timeout    = 500;
var closetimer = 0;
var ddmenuitem = 0;

function jsddm_open()
{  jsddm_canceltimer();
   jsddm_close();
   ddmenuitem = $(this).find('ul').css('visibility', 'visible');}

function jsddm_close()
{  if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

function jsddm_timer()
{  closetimer = window.setTimeout(jsddm_close, timeout);}

function jsddm_canceltimer()
{  if(closetimer)
   {  window.clearTimeout(closetimer);
      closetimer = null;}}

$(document).ready(function()
{  $('#nav > li').bind('mouseover', jsddm_open)
   $('#nav > li').bind('mouseout',  jsddm_timer)});

document.onclick = jsddm_close;

jQuery.fn.anchorAnimate = function(settings) {

 	settings = jQuery.extend({
		speed : 400
	}, settings);	
	
	return this.each(function(){
		var caller = this
		$(caller).click(function (event) {	
			event.preventDefault()
			var locationHref = window.location.href
			var elementClick = $(caller).attr("href")
			
			// Hazar tarafından eklendi: URL + Anchor geldiğinde düzgün çalışması için ayar.
			ilkAdres = window.location.pathname + window.location.search
			ilkAdres = ilkAdres.substring(ilkAdres.lastIndexOf('/')+1);			
			sonAdres = elementClick.substring(0, elementClick.lastIndexOf('#'));
			
			
			if (ilkAdres != sonAdres) {
				// Direk yönlendirme.
				window.location = elementClick;
				return false;
			} else {
				elementClick = elementClick.substring(elementClick.lastIndexOf('#'))
			}			
			// Hazar tarafından eklendi: URL + Anchor geldiğinde düzgün çalışması için ayar.
			
			var destination = $(elementClick).offset().top;
			
			var domdom = ($.browser.opera) ? "html:not(:animated)" : "html:not(:animated),body:not(:animated)";
			$(domdom).animate({ scrollTop: destination}, settings.speed, function() {
				window.location.hash = elementClick
			});
		  	return false;
		})
	})
}

function yukseklikAyarla() {
	var fark = 0;
	if ($("#genisorta").height() > getSolDivHeight()) fark = ($("#genisorta").height() - getSolDivHeight()); // Fark var..
	if ($("#darsol").length > 0 && $("#darsol").height() < getSolDivHeight()+fark) $("#darsol").css({"height" : getSolDivHeight()+fark + "px"});
	}
	
function getSolDivHeight() {
	var sabit
	sabit = 225
	return (getViewportHeight() - sabit <= 0) ? 0 : getViewportHeight() - sabit;
	}

function numVld(evt)
{
	var charCode = (evt.which) ? evt.which : event.keyCode
	if (charCode > 31 && (charCode < 48 || charCode > 57)) return false;	
	else return true;
}

function priceVld(evt)
{
	var charCode = (evt.which) ? evt.which : event.keyCode
	if (charCode == 44) return true;
	else {
		if (charCode > 31 && (charCode < 48 || charCode > 57)) return false;
		else return true;
	}
}

function getViewportHeight() {
	var viewportwidth;
	var viewportheight;
	
	// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	
	if (typeof window.innerWidth != 'undefined')
	{
	  viewportwidth = window.innerWidth,
	  viewportheight = window.innerHeight
	}
	
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	
	else if (typeof document.documentElement != 'undefined'
	 && typeof document.documentElement.clientWidth !=
	 'undefined' && document.documentElement.clientWidth != 0)
	{
	   viewportwidth = document.documentElement.clientWidth,
	   viewportheight = document.documentElement.clientHeight
	}
	
	// older versions of IE
	
	else
	{
	   viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
	   viewportheight = document.getElementsByTagName('body')[0].clientHeight
	}
	return viewportheight;
}

function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,directories=no,width=820,height=670,left = 430,top = 195');");
}