/**
 * common.js
 * ismail ŞAHAN
 * Modified Date: 2010-06-30 17:34:21
*******************************************/
var Nav = {
		_over : function(item) {
			var el = $(this);
				el.find('.sub:first').stop().fadeTo('fast', 1).show();
				el.find('.item:first').addClass('active');
		},
		_out : function(item) {
				var el = $(this);
				el.find('.sub:first').stop().fadeTo('fast', 0, function() {
				  $(this).hide(); 
			  });
			 el.find('.item:first').removeClass('active');
		}
	};
(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="pagination">');
			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 = '';
				if(j == 0) current = 'current';
				var $a = $('<a href="#'+(j)+'" class="spr-skin slide-link '+current+'">'+(j+1)+'</a>').click(function(){
					if(el.opt.autoplay){
						window.clearInterval(el.tID);
						autoplay();
					}
					var href = this.index;
					el.pagination.find('.current').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;
				

				$('<li class="slideIS-item">').appendTo(num).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');*/
				
			 });
			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();
						}	
					},7000)
			}
		});	
	}
SlideIS = {
		ease: 'easeInOutExpo',
		speed:1000,
		delay:null,
		autoplay:null,
		height: 185,
		width: 592,
		direction : 'vertical' // vertical horizontal
	};	
})(jQuery);


function _showStore(A){
		var F= $('.list'),
			G= $('#province ul.sub')
			B = F.find('dt'),
			C =  F.find('dd'),
			D = $('#province a.item');
			var T = A,
				A = $('[name='+A+']'),
				I= $(A).first().attr('rel'),
				J = $('.province-image img'),
				E = A.next('dd');

				B.hide();
				C.hide();
				A.show();
				E.show();
				D.html(T).removeAttr('title');
				D.removeAttr('onclick');
				if(I.length>0){
				J.attr('src', '/images/stores/'+I)
				}else{
				J.attr('src', '/images/stores/no-photo.png')
				}
}

function validateHr(){
	$("#frm-hr").validate({
			rules: {
				hrname: "required",
				hrsurname: "required",
				hrphone: {
					required: true,
					number: true,
					minlength: 10,
					maxlength: 14
				},
				hremail: {
					required: true,
					email: true
				},
				hrconditionsconfirm: "required"
			},
			messages: {
				hrname: "* "+Utily._e('req_name'),
				hrsurname: "* "+Utily._e('req_surname'),
				hrphone: "* "+Utily._e('req_phone'),
				hremail: "* "+Utily._e('req_email'),
				hrconditionsconfirm:"* "+Utily._e('req_confirm')
			}
		});
}

var LoadMore ={
	content 		: 'main-posts',
	itemClass 		: 'post-item',
	start 			:20,
	desiredPosts 	:5,
	url			 	:null,
	init			: function(content, itemClass, start,desiredPosts,url){
		var initialPosts 	= [{"post_title":"MooTools Star Ratings with MooStarRating","post_content":"I've said it over and over but I'll say it again: ","post_name":"mootools-star-rating","ID":"5166"},{"post_title":"Translate Content with the Google Translate API and JavaScript","post_content":"Note: ","post_name":"google-translate-api","ID":"5165"},{"post_title":"Google URL Shortener PHP Class","post_content":"Google has had a URL shortening domain for quite a while now but it wasn't until recently that Google exposed the URL shortening API to the public. ","post_name":"google-url","ID":"5162"},{"post_title":"Link Nudging with CSS3 Animations","post_content":"One of the more popular and simple effects I've featured on this blog over the past year has been linking nudging. ","post_name":"css-link-nudging","ID":"5147"},{"post_title":"window.postMessage Tip:  Child-To-Parent Communication","post_content":"I wrote a super epic post a few months back about the window.postMessage API that's sweeping the nation. ","post_name":"window-iframe","ID":"5161"},{"post_title":"Create an Exploding Logo with CSS3 and MooTools or jQuery","post_content":"When MooTools contributor and moo4q creator Ryan Florence first showed me his outstanding CSS animation post, I was floored. ","post_name":"css-explode","ID":"5157"},{"post_title":"Conditional CSS with MooTools' Browser Object","post_content":"Whether we want to admit it or not, we all need a bit of browser-specific or even version-specific CSS sometimes. ","post_name":"mootools-css","ID":"5160"},{"post_title":"Script Junkie:  MooTools Class Creation and Organization","post_content":"My new blog post has debuted on Script Junkie: MooTools Class Creation and Organization!!","post_name":"script-junkie-mootools","ID":"5158"},{"post_title":"Force Login to View WordPress Blog Pages","post_content":"I was recently working on a private \/ \"closed\" website that featured WordPress. ","post_name":"wordpress-force-login","ID":"5155"},{"post_title":"Delay AJAX Searches with JavaScript's setTimeout","post_content":"I was recently creating a custom Dijit widget that required that a list get filtered during each keystroke instead of using the usual \"Submit\" button. ","post_name":"javascript-settimeout","ID":"5152"},{"post_title":"Create Spinning, Fading Icons with CSS3 and jQuery","post_content":"Last week I debuted a popular blog post titled Create Spinning, Fading Icons with CSS3 and","post_name":"fade-spin-css3-jquery","ID":"5154"},{"post_title":"Thoughts on Mobile Devices","post_content":"Whether I'm smug enough to admit it or not, I'm living the iLife. ","post_name":"mobile-devices","ID":"5153"},{"post_title":"Create Spinning, Fading Icons with CSS3 and MooTools","post_content":"A goal of my latest blog redesign was to practice what I preached a bit more; ","post_name":"css-spin","ID":"5150"},{"post_title":"MooTools ASCII Art","post_content":"I didn't realize that I truly","post_name":"mootools-ascii-art","ID":"5148"},{"post_title":"Dive Into Dojo Series: Dive Into Dojo GFX","post_content":"I just wanted to give everyone a heads up about my latest Dive Into Dojo post: Dive Into Dojo GFX!","post_name":"dojo-gfx","ID":"5149"},{"post_title":"MooTools ScrollSpy, Mobile Devices, JavaScript Scroll Events, and CSS Positioning","post_content":"One question I've been asked often is why ScrollSpy and my Go To Top link functionality don't appear to work well on the iPhone, iPad, or any other mobile device. ","post_name":"scrollspy-mobile","ID":"5145"},{"post_title":"HTML5 Placeholder Styling with CSS","post_content":"Last week I showed you how you could style selected text with CSS. ","post_name":"html5-placeholder-css","ID":"5146"},{"post_title":"Debug Element Modification in MooTools by Monkey Patching Prototypes","post_content":"Let's face it: ","post_name":"debug-mootools","ID":"5144"},{"post_title":"Create Spinning Rays with CSS3 Animations & JavaScript","post_content":"Thomas Fuchs, creator of script2 (scriptaculous' second iteration) and Zepto.js (mobile JavaScript framework), creates outstanding animated elements with JavaScript. ","post_name":"javascript-spin","ID":"5143"},{"post_title":"Customize Textarea Resizing with CSS","post_content":"Webkit-based web browsers like Safari and Chrome have led web innovation the past few years. ","post_name":"textarea-resize","ID":"5140"}];
		this.content = $('#'+content);
		this.itemClass = itemClass;
		this.start = start;
		this.desiredPosts = desiredPosts;
		this.url = url;
		this.postHandler(initialPosts);
	},
	postHandler 	: function(postJson){
		$.each(postJson, function(i,post){
			var url = post.post_name,
				id= LoadMore.itemClass+'-'+ post.ID;
				$('<div></div>').addClass(LoadMore.itemClass).attr('id',id).html(' <div class="post-img fl"> <div class="post-img-bg sp-home"></div><img src="static/post/1.jpg" alt="" /> </div><div class="post-txt"><h3 class="post-title"><a href="'+url +'" title="'+ post.post_title+'">'+ post.post_title+'</a></h3><p class="post-desc">'+post.post_content +'</p></div>')
				.click(function(){
						window.location= url;		
				})
				.appendTo(LoadMore.content)
				.hide()
				.slideDown(250, function(){
					if(i=0){
						$.scrollTo($('#div'+id));
					}
				});
				
		});
		this.more();
	},
	more : function(){
		LoadMore.content.find('.load-more').bind('click', function(){
			var el  = $(this);
			el.addClass('activate').text('yükleniyor...');  
			$.ajax({
				url : LoadMore.url,
				data: {
						'start' : LoadMore.start,
						'desiredPosts' : LoadMore.desiredPosts
					},
				type: 'get',
				dataType:'json',
				succes : function(data){
						el.text('yükle');  
						LoadMore.start += LoadMore.desiredPosts;  
						LoadMore.postHandler(data);  
				},
				error: function() {  
					el.text('Oops!');  
				}, 
				complete : function(){
					el.removeClass('activate');
				}
			
			})
		})

	}
	
}



