var slide_width;
var slide_duration;
var slide_interval_duration;
var slide_interval;
var slideCell;

$(document).ready(function() {

	// redefine left nav links
   $('.nav_link_static').attr({'href': 'javascript:void(0)'});

   $('.breadcrumb-link .static').attr({'href': 'javascript:void(0)'});

   //$('#nav_13 li').hover(function() {
   //   $(this).find('span').show('slow').end().find('a').addClass('selected-nav');


   $('#nav_13 a').hover(function() {
      $(this).parent().find('span').show('slow').end().addClass('selected-nav');
   },function(){
      $('#nav_13 span').hide('fast');
	  $('#nav_13 a').removeClass('selected-nav');
   });

   $('#nav_113 a').hover(function() {
      $(this).parent().find('span').show('slow').end().addClass('selected-nav');
   },function(){
      $('#nav_113 span').hide('fast');
	  $('#nav_113 a').removeClass('selected-nav');
   });


   $('#news-slide').gcltxtslider({
		wrapperWidth  :695,
		contentWidth  :1200,
		contentTag    :"div",
		slideDuration :35000

   });


/**
   $('#news-slide').gcltxtslider({
		wrapperWidth  :695,
		contentWidth  :1980,
		contentTag    :"div",
		slideDuration :35000
   });

*/
    // news scroller
    //slideCell = $("#news-slide-list");
    //slide_width = slideCell.width();


/*
	if(slide_width < 700) {
		slide_duration = 11000;
	}
	else {
		slide_duration = slide_width / 700;
		slide_duration = Math.round(slide_duration);
		slide_duration = slide_duration*11000;
	}
	slide_width += 690;
*/

	//slide_duration = 30000;
	//slide_interval_duration = 29000;

	//slide_duration = 25000;
	//slide_interval_duration = 21400;

	//headline_rotate();
	//slide_interval = setInterval(headline_rotate, slide_interval_duration);



    // newsletter form process code
	/*$('#loadingCell').ajaxStart(function() {
      $(this).show();
    }).ajaxStop(function() {
      $(this).hide();
    });*/

  	$('#newsletter').submit( function() {
	  var emailVal = $('#nl_email').val();
	  if ( (emailVal.length > 0) && validateEmail(emailVal) ) {
	    $.post("/form_handler.php",
	      { email_value: emailVal, form_id: "newsletter", form_wrapper_id: "nl_form", result_wrapper_id: "submissionResultCell" },
	        function(data){
			  eval(data);
	        }
	    );
	  } else {
	    $('#nl_email').focus();
	    alert ('Lütfen email adresinizi kontrol edip tekrar giriniz');
	  }
	  return false;
  	});

});

/******tooltip*******/

var gcltt_links;
var $gcltt;

var gclttposlt =  new Array(); // glacial tooltip position left top
var gclttwh = new Array(); // glacial tooltip width height
var gcldocwh = new Array(); // document width height


$(document).ready(function() {
	$(".gcltt_link").attr({'href': 'javascript:void(0)'});
	gclttwh[0]=250;
	gclttwh[1]=175;

	$('.gcltt_link').hover(function(e) {
		gcldocwh[0] = $(document).width();
		gcldocwh[1] = $(document).height();

		// right / left of cursor
		if((gcldocwh[0] - e.pageX - gclttwh[0]) > 4 ) { gclttposlt[0] = e.pageX+3; } else { gclttposlt[0] = e.pageX - gclttwh[0] - 3; }

		// bottom / top of cursor
		if((gcldocwh[1] - e.pageY - gclttwh[1]) > 4 ) { gclttposlt[1] = e.pageY+3; } else { gclttposlt[1] = e.pageY - gclttwh[1] - 3; }

		$('.gcl_tooltip').hide();
		$gcltt = $('#'+$(this).attr("id") + "_tt");
		$gcltt.show();
		$gcltt.css({ top:gclttposlt[1], left:gclttposlt[0] });
	},function(){
		$gcltt.hide();
		$gcltt = null;
		gclttposlt[0] = null;
		gclttposlt[1] = null;
		gcldocwh[0] = null;
		gcldocwh[1] = null;
	});
});
/******tooltip*******/





function validateEmail(fieldValue, fieldObj) {
   if (fieldValue == "") return true;
   return /\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/.test(fieldValue);
}

function menushow(nNav,depth,nChild) {
   if(nChild > 0) {
	   $('#nav_'+posNav).slideUp('slow',function() {
		  $('#leftCol ul').hide();
		  $('#nav_'+nNav).slideDown('slow');
	   });

   }
   else {
	   /*$('#nav_'+posNav).slideUp('slow',function() {
		  $('#nav_'+posNav).slideDown('slow');
	   }); */
	   $('#nav_'+posNav).slideUp('slow').slideDown('slow');
   }

   posNav = nNav;
   generateBreadcrumb(nNav,depth,nChild)
   return(false);
}

function generateBreadcrumb(nNav,depth,nChild) {
   var bc=depth+1;
   $('#breadcrumbs span').each(function(index) {
      if( depth < index ) { $(this).html('&nbsp;'); }
   });

   if(depth !=0) {
       $('#breadcrumb-'+depth).html('<a class="breadcrumb-link" href="javascript:void(0)" onclick="menushow('+nNav+','+depth+','+nChild+')">' + $('#nav_item-'+nNav).text() + '</a>');
   }
}

function headline_rotate() {
//	slideCell.css('left', '697px').animate({ left:'-='+slide_width }, slide_duration );
slideCell.css('left', '697px').animate({left:'-1020px'}, { duration: slide_duration, easing: "linear", queue: false });

}



function goster_tezgah(type, id, parent, hide_child) {

    $('.worktopHeaderContainer li p').hide();
    $('#header-item-'+id+' p').fadeIn('normal');

    if(type==2) {
		$('#tezgahlar-child div').hide();
		$('#tezgahlar-color div').hide();
		$('#tezgahlar-child').show();
		$('#tezgahlar-child-'+id).fadeIn('normal');
	}
	else if(type==3) {
		if(hide_child==1) {
			$('#tezgahlar-child').hide();
			$('#tezgahlar-child div').hide();
		}
		$('#tezgahlar-color div').hide();
		$('#tezgahlar-color').show();
		$('#tezgahlar-color-'+id).fadeIn('normal');

		$('#header-item-'+parent+' p').show();

	}

	$('#nav_14 a').removeClass('selected-nav');
	$('#nav_114 a').removeClass('selected-nav');
	$('#tezgah-link-'+parent).addClass('selected-nav');

	$('#tezgahlar-parent li').removeClass('selected-item');
	$('#tezgahlar-parent li').addClass('disabled-item');

	$('#tezgah-item-'+parent).removeClass('disabled-item');
	$('#tezgah-item-'+parent).addClass('selected-item');
}



/////////////////////////////////////////////////////////////////////////
// [JQuery SLIDER Plugin] ///////////////////////////////////////////////
(function($) {
$.fn.gcltxtslider = function(options) {

	var defaults = {
		wrapperWidth  :950,
	    contentWidth  :950,
	    contentTag    :"div",
		slideDuration   :40000,
		stopOnMouseOver :false
	},
    settings = $.extend({}, defaults, options),
	$this = $(this), $contents, slideInterval;

	$this.find(settings.contentTag).clone().appendTo($this); //.clone().appendTo($this);
	$contents = $this.find(settings.contentTag).css('left', settings.wrapperWidth+'px');

	slideInterval = settings.slideDuration / 2;

	content_slide(0);
	setTimeout(function() {content_slide(1)}, slideInterval);
	//setTimeout(function() {content_slide(2)}, (slideInterval * 2));
	function content_slide(n) {
		if ( (typeof(n) == 'undefined') || n===null ) { n = 0; }
		$contents.eq(n).css('left', settings.wrapperWidth+'px').animate({left: -settings.contentWidth+'px'},settings.slideDuration, 'linear', function() {
			content_slide(n);
		});
	}

	// returns the jQuery object to allow for chainability.
    return this;
};
})(jQuery);







// CSS Browser Selector   v0.2.5
// Documentation:         http://rafael.adm.br/css_browser_selector
// License:               http://creativecommons.org/licenses/by/2.5/
// Author:                Rafael Lima (http://rafael.adm.br)
// Contributors:          http://rafael.adm.br/css_browser_selector#contributors
var css_browser_selector = function() {
	var
		ua=navigator.userAgent.toLowerCase(),
		is=function(t){ return ua.indexOf(t) != -1; },
		h=document.getElementsByTagName('html')[0],
		b=(!(/opera|webtv/i.test(ua))&&/msie (\d)/.test(ua))?('ie ie'+RegExp.$1):is('gecko/')? 'gecko':is('opera/9')?'opera opera9':/opera (\d)/.test(ua)?'opera opera'+RegExp.$1:is('konqueror')?'konqueror':is('applewebkit/')?'webkit safari':is('mozilla/')?'gecko':'',
		os=(is('x11')||is('linux'))?' linux':is('mac')?' mac':is('win')?' win':'';
	var c=b+os+' js';
	h.className += h.className?' '+c:c;
}();
