/**
Generated	: April 19th 2010 09:34:32
ismail ŞAHAN
********************************************************************************************/


/**
 * jQuery .is(':visible') bug fixed
*********************************************************************************/
 jQuery.extend(
    jQuery.expr[ ":" ],
    { reallyvisible : function (a) {
return !(jQuery(a).is(":hidden") || jQuery(a).parents(":hidden").length || jQuery(a).css('display')=='none');
 }}
  );
 //image
 (function(){
	var db=document.body;
	var img=document.getElementById('holder').getElementsByTagName('img')[0];
	

	var dbsize={}; //needed to store body size
	var imgsrc=img.src; //needed to store images src
	var keyStop=function(e){
		var e=window.event||e||{};
		var tag=e.target.tagName.toLowerCase();
		if(tag!='textarea'&&!(tag=='input'&&(e.target.type=='text'||e.target.type=='password'))){ //are the user not writing?
			if(e.keyCode==32||e.keyCode==39||e.keyCode==40){ //Did he press any of the "scrolling-keys"? (down, right, and space key)
				if(e.preventDefault)e.preventDefault();
				else e.returnValue=false;
			}
		}
	}

	if(this.addEventListener)window.addEventListener('keydown',keyStop,false);
	else window.attachEvent('onkeydown',keyStop);

	setInterval(function(){
		window.scrollTo(0,0);
		if(img.complete){ //check if image has loaded
			if(db.clientWidth!=dbsize.w||db.clientHeight!=dbsize.h||img.src!=imgsrc){ //check if size or img size has changed
				imgsrc=img.src; //store current src
				dbsize.w=db.clientWidth; //store current body width
				dbsize.h=db.clientHeight; //store current body height

				var newwidth=Math.round(dbsize.h*(img.offsetWidth/img.offsetHeight)); //calculate new width based on height

				img.style.width=(dbsize.w>newwidth?dbsize.w:newwidth)+'px'; //use the largest value of body-width and newwidht
				//and this is the real trick: if there's no specified height, the height is automaticly calculated relative to the with
				img.className = '';
			}
		}
	},300);
})();
(function(){
	$.fn.GalleryCarausel = function(){
		 function repeat(str, num) {
        return new Array( num + 1 ).join( str );
    }
  
    return this.each(function () {
        var $wrapper = $('> div', this).css('overflow', 'hidden'),
            $slider = $wrapper.find('> ul'),
            $items = $slider.find('> li'),
            $single = $items.filter(':first'),
			$list =  $items.find('> .thumb'),
            
            singleWidth = $single.outerWidth(), 
            visible = Math.ceil($wrapper.innerWidth() / singleWidth),
            currentPage = 1,
            pages = Math.ceil($items.length / visible);            


        if (($items.length % visible) != 0) {
            $slider.append(repeat('<li class="empty" />', visible - ($items.length % visible)));
            $items = $slider.find('> li');
        }

        $items.filter(':first').before($items.slice(- visible).clone().addClass('cloned'));
        $items.filter(':last').after($items.slice(0, visible).clone().addClass('cloned'));
        $items = $slider.find('> li'); // reselect
        
        $wrapper.scrollLeft(singleWidth * visible);
        
        function gotoPage(page) {
            var dir = page < currentPage ? -1 : 1,
                n = Math.abs(currentPage - page),
                left = singleWidth * dir * visible * n;
            
            $wrapper.filter(':not(:animated)').animate({
                scrollLeft : '+=' + left
            }, 500, function () {
                if (page == 0) {
                    $wrapper.scrollLeft(singleWidth * visible * pages);
                    page = pages;
                } else if (page > pages) {
                    $wrapper.scrollLeft(singleWidth * visible);
                    page = 1;
                } 

                currentPage = page;
            });                
            
            return false;
        }
        
       // $wrapper.after('<a class="arrow back">&lt;</a><a class="arrow forward">&gt;</a>');
        
        $('a.back', this).click(function () {
            return gotoPage(currentPage - 1);                
        });
        
        $('a.forward', this).click(function () {
            return gotoPage(currentPage + 1);
        });
        
        $(this).bind('goto', function (event, page) {
            gotoPage(page);
        });
		$list.bind('click',function(){
									
				var $rel = $(this).attr('rel'),
				$fullsize = $('#fullsize-image'),
				$src =  'resources/i/'+$rel;
				$fullsize.addClass('loading');
				var img = new Image();
				$(img).load(function () {
					//$(this).css('display', 'none'); // .hide() doesn't work in Safari when the element isn't on the DOM already
					$(this).hide();
					$fullsize.removeClass('loading').html(this);
					$(this).fadeIn();
					}).error(function () {
				}).attr('src', $src);							
			});
    });  

	} ;
})(jQuery);
 
 (function($) {
	$.fn.SlideIS = function(options){
		return this.each(function(i){
			var el = this
			el.current =  0;
			el.$this = $(this).css({position:'relative'});
			el.list = el.$this.find('.slide-item');
			el.opt = $.extend({}, SlideIS, options);
			el.index = i;
			el.total = el.list.size();
			el.tID = null;
			var w,h;
			switch(el.opt.direction){
				case 'horizontal':
					width = el.total * el.opt.width;
					height = el.opt.height;
					break;
				case 'vertical':
					width = el.opt.width;
					height = el.total *el.opt.height;
					break;
				default:
					width = el.total *el.opt.width;
					height = el.total *el.opt.height;
					break;
			};
			el.itemContainer = $('<div class="item-container" style="height:'+el.opt.height+'px;position:relative;overflow:hidden">')
								.css({height:el.opt.height,width:el.opt.width,position:'relative',overflow:'hidden'});
			el.$this.css({height:height,width:width});
			
			el.$this.wrap(el.itemContainer);
			el.pagination = $('<div class="paging paging2">');
			el.$this.parent().parent().append(el.pagination);
			//var num = $('<ul class="pages">').appendTo(el.pagination);
			var pos = {x:0,y:0};
			var n;
			el.list.each(function(j){
			 	var current = '',
					$first = '';
				if(j == 0) current = 'current';
				if(j != 0) $first = ' - ';
				
				var $a = $('<a href="#'+(j)+'" class="num slide-link '+current+'">'+($first)+(j+1)+'</a>');
				$a.click(function(){
					if(el.opt.autoplay){
						window.clearInterval(el.tID);
						autoplay();
					}
					var href = this.index;
					$('.paging').find('.num').removeClass('current');
					$(this).addClass('current');
					
					var params = {};
					if( el.opt.direction == 'diagonal'){
						params = {right:(el.opt.width*href),bottom:(el.opt.height*href)}
					}
					else if( el.opt.direction == 'vertical'){
						params = {bottom:(el.opt.height*href)}
					}
					else if( el.opt.direction == 'horizontal'){
						params = {right:(el.opt.width*href)}
					};
					el.$this.stop().animate(params,{
					  duration: el.opt.speed,
					  easing: el.opt.ease, 
					  complete: function() { 
					  	// alert('ok');
					  }
					 });
					el.index = href;
					return false;
				});
				
				n = $a.get(0);
				n.index = j;
				el.pagination.append($a);
				

				if( el.opt.direction == 'diagonal'){
					pos.x = j * el.opt.width;
					pos.y = j * el.opt.height;
				}
				else if( el.opt.direction == 'horizontal'){
					pos.x = j * el.opt.width;
				}
				else if( el.opt.direction == 'vertical'){
					pos.y = j * el.opt.height;
				};

				var list = $(this).css({height:el.opt.height,width:el.opt.width,position:'absolute',left:pos.x, top:pos.y});
				list.show();
				/*var $loader = $('<div class="loading">').appendTo(list);
				var image = new Image();
				image.onload = function(){
					image.onload = null;
					$loader.fadeOut();
					img.css({marginLeft:-image.width*.5,marginTop:-image.height*.5,position:'absolute',left:'50%',top:'50%'}).fadeIn();
					var alt = img.attr('alt');
					if(typeof alt != 'undefined'){
						//$titleHolder.text(alt).fadeIn();
					}
				};
				image.src = img.attr('src');*/
				
			 });
			//$('#pager').html($('.paging2').html());
			
			if(el.opt.autoplay){
				window.clearInterval(el.tID);
				autoplay();
			}
			function autoplay(){
					el.tID = window.setInterval(function(){
						var next = parseInt(el.index + 1);
						if((el.index + 1) == el.total){
							el.pagination.find('[href$=#0]').click();
							
						}
						else{
							el.pagination.find('[href$=#'+next+']').click();
						}	
					},3000)
			}
		});	
	}
SlideIS = {
		ease: 'easeInOutExpo',
		speed:1000,
		delay:null,
		autoplay:null,
		height: 185,
		width: 592,
		direction : 'horizontal' // vertical horizontal
	};	
})(jQuery);
 
 $('.news #back-page').bind('click',function(){
		$('#news-detail-ajax').addClass('dn');
		$(this).addClass('dn');
		gui.dom.news.removeClass('dn');
})
  
 $('.product #back-page').bind('click',function(){
		$('#main-content2').addClass('dn');
		$(this).addClass('dn');
		gui.dom.mc.removeClass('dn');
})

function validateHr(e){
	var el = $(e);
	var email = el.find("#hr-mail").val();
	var name = el.find("#hr-name").val();
	var errMail = el.find("#hr-err-mail");
	var errName = el.find("#hr-err-name");
	var err= true;
	errMail.html('');
	errName.html('');
	if (name.length<1 || name==el.find("#hr-name").attr('title')){
		err = false;
		errName.html('Ad ve soyad alanını boş geçemezsiniz');
		var cssObj = {
		  'color' : '#FF0000','font-size' : '11px','display' : 'block'}
		errName.css(cssObj);
	}
	if(!isValidEmailAddress(email)){
		errMail.html('Sana ulaşabilmemiz için geçerli bir e-mail adresi girmelisin');
		var cssObj = {
		  'color' : '#FF0000','font-size' : '11px','display' : 'block'}
		errMail.css(cssObj);
		err = false;
		
	}
	if(!err){
		return false;
	}
}

function isValidEmailAddress(emailAddress) {
var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
return pattern.test(emailAddress);
}
function initFadeImg(el){
	var list = $(el)
	list.click(function(){
		//window.location= $(this).find('a').attr('href');
	}).mouseover(function(){
		var el = $(this);  
		el.addClass('active');
		el.find('img').stop().animate({ opacity: 1 }, 300);
	}).mouseleave(function () {
		var el = $(this);
		list.find('img').stop().animate({ opacity: .5 }, 500);  
		el.removeClass('active');
	});
}

function inputHandler(searchField){
	searchField.focus(function() {
		$(this).addClass("fc");
		if (this.value == this.title){
			this.value = '';
		}
		if(this.value != this.defaultValue){
			this.select();
		}
	});
	searchField.blur(function() {
		if ($.trim(this.value) == ''){
			$(this).removeClass("fc");
			$(this).val('');
			//this.value = (this.title ? this.title : '');
			this.value = this.title;

		}
	});
}

$('.thumb').bind('click',function(){
	var img = new Image();
	var imgHref= $(this).attr('rel');
	imgHref = 'resources/i/galeri/buyuk/'+imgHref;
       $(img).load(function () {
            $(this).hide();
            //$('#loader').removeClass('loading').append(this);
			gui.dom.fi.html(this);
            $(this).fadeIn();
        }).error(function () {
            // error
        }).attr('src', imgHref);								   
})

