//start slider
$(document).ready(function(){
	//Set the opacity of all images to 0
	$('#manifesto-slides li').hide();
	
	$('#manifesto-slides li:first').show().addClass('show');
	
	var ht='';
	
	$('#manifesto-slides li').each(function(index) {
      ht = ht + '<a href="#'+$(this).attr("id")+'">' + index + '</a>';
    });
	
	$(".menu").html(ht);
	
	$('.menu a:first').addClass('current-slide');
	
	$(".menu a").click(function(event) {
      event.preventDefault();
	  $('.menu a').removeClass('current-slide');
	  $(this).addClass('current-slide');
	  
	  var current = $('#manifesto-slides li.show');
	  
	  var d=$(this).attr('href').split("#")[1];

	  current.hide().removeClass('show');
	  
	  $('#'+d).fadeIn().addClass('show');

    });
	
	$('#manifesto-slides li.show').show();  //show class show frame
});

//end slider

//start navigator
var amountVisible=function(c){var a=$(window).scrollTop();
var b=a+$(window).height();
var e=c.offset().top;
var d=e+c.height();
if(d>a&&d<b){return d-a}else{return b-e}};

var fetchMatchingNavItem=function(a){
  return $("#"+$(a).attr("id")+"-link").parent()
};

var setCurrentClass=function(a){
  a.addClass("current");
  a.siblings("#nav li").removeClass("current");
  
  if ((a.attr("id") == '#connect') || (a.attr("id") == '#what-we-do')) {
    $('#nav li a').css('color','#002d4f');
    $('#nav li a').css('text-shadow','0 1px 0 rgba(112, 174, 203, .7)');
  }
    else
  {
    $('#nav li a').css('color','#063c66');
    $('#nav li a').css('text-shadow','0px 1px 1px #8cc8e4');
  };
  
  $('#nav li.current a').css('color','#A5E1FF');
  $('#nav li.current a').css('text-shadow','0 1px 0 rgba(0, 0, 0, .7)');
};

$(document).ready(function(){
	$("#logo").click(function(event) {
    event.preventDefault();
	$.scrollTo("#header",800);
    });

    $(window).bind("scroll", function(event) {
	
	var a=null;
    var b=$(".scroll-item:in-viewport");
	
	b.each(function(c){var d=$(this);
      if(a==null||amountVisible(d)>=amountVisible(a)){a=d}})

    setCurrentClass(fetchMatchingNavItem(a));
    });

    $("#waterstudio #nav ol li a").click(function(event) {
        event.preventDefault();
    	var d=$(this).attr('href').split("#")[1];
    	$.scrollTo("#"+d,800);
    });
    
    $(document).keydown(function(d){
	  switch(d.keyCode){
	    case 39:
		  var current = $('.current');
		  var next = current.next();
		  var d=next.attr('id').split("#")[1];
		  var nex = $('#' + d);
		  
		  $.scrollTo(nex,800)
		  break;
		case 37:
		  var current = $('.current');
		  var next = current.prev();
		  var d=next.attr('id').split("#")[1];
		  var nex = $('#' + d);
		  
		  $.scrollTo(nex,800)
		  break;
	  }
	});


});
//end of navigator

//start skills
$(document).ready(function(){
		$('.php').animate({ marginLeft: '-20px' }, 5000 );
		$('.htmlcss').animate({ marginLeft: '-10px' }, 5000 );
		$('.mysql').animate({ marginLeft: '-25px' }, 5000 );
		$('.wp').animate({ marginLeft: '-35px' }, 5000 );
		$('.js').animate({ marginLeft: '-50px' }, 5000 );
		$('.ajax').animate({ marginLeft: '-90px' }, 5000 );
		$('.photoshop').animate({ marginLeft: '-100px' }, 5000 );
		$('.illustrator').animate({ marginLeft: '-110px' }, 5000 );
		
		$('ul.graphics li').mouseover(function(){
			$(this).css({'background-color' : '#064567'});
		});
		$('ul.graphics li').mouseout(function(){
			$(this).css({'background-color' : '#053F5E'});
		});
		
		var name = "tooltip";
		
		$(".graphics a").each(function(i){
		$("body").append("<div class='"+name+"' id='"+name+i+"'>"+$(this).attr('title')+"</div>");
		var my_tooltip = $("#"+name+i);

		$(this).removeAttr("title").mouseover(function(){
				my_tooltip.css({opacity:0.8, display:"none"}).show();
		}).mousemove(function(kmouse){
				my_tooltip.css({left:kmouse.pageX+15, top:kmouse.pageY+15});
		}).mouseout(function(){
				my_tooltip.hide();
		});
	    });

});
//end of skills

//start porfolio
$(document).ready(function(){
  $(".content").hide();
  $(".content:first").show().addClass('show');

  $(".a-right").click(function(event) {
    event.preventDefault();
	
	var current = $(".content.show");
	var next = current.next('.content');
	
	if (next.length) {
	  current.hide().removeClass('show');
	  next.fadeIn().addClass('show');
	};
  });
  
  $(".a-left").click(function(event) {
    event.preventDefault();
	
	var current = $(".content.show");
	var next = current.prev('.content');
	
	if (next.length) {
	  current.hide().removeClass('show');
	  next.fadeIn().addClass('show');
	};
  });

});
//end of porfolio

$(document).ready(function(){
$.getJSON('http://allmovies.ge/ge/#index', function(data) {
  var items = [];

  $.each(data, function(key, val) {
    items.push('<li id="' + key + '">' + val + '</li>');
  });

  $('<ul/>', {
    'class': 'my-new-list',
    html: items.join('')
  }).appendTo('body');
});

});
//end of porfolio

//-------
$(document).ready(function(){

$('.droper').click(function() {
  $('#combo ul').toggle();
});

$('#combo ul li').click(function() {
  $('#ptype').attr('value', $(this).attr('id'));
  $('#combo ul').hide();
});

$(document).click(function(event) {
   if (!$(event.target).is('#combo ul, .droper')) { 
     $('#combo ul').hide();
   } 
});

  $('#ptype').example(function() {
    return 'ტიპი';
  });

  $('#pname').example(function() {
    return 'სახელი';
  });
  
  $('#pmail').example(function() {
    return 'ელ. ფოსტა';
  });
  
  $('.list-email').example(function() {
    return $(this).attr('title');
  });
  
  $('.feed-memo').example('Type here...', {
  className: 'not_example'
  });

	$(".send-button").click(function () {
	  var ntitle = $('#pname').val();
	  var nmail = $('#pmail').val();
	  var nptype = $("#ptype").val() || [];
	  
	  //get template patch
	  var templatepatch = $('#templatepatch').val();
	  var root = $('#root').val();
	  var template = templatepatch.replace(root+"/", "");
	  
	  
	  
      $.ajax({
	  
      type: "POST",
      url: template + "/ajax/post-insert.php?post_title="+ntitle+"&post_mail="+nmail+"&post_type="+nptype+"&nocache=no",
      data: ntitle,
	  
      success: function(msg){
	  $(".send-notifer").html('Sent successfully!!!').fadeIn().delay(3000).fadeOut(2000);

      }
    });
    });
	
	//----------
	
	
	$(".list-email").keydown(function(d) {
	
	if (d.keyCode == 13) {
	
	
	var l_email = $('.list-email').val();
	
	//get template patch
	var templatepatch = $('#templatepatch').val();
	var root = $('#root').val();
	var template = templatepatch.replace(root+"/", "");
	
      $.ajax({
	  
	  
      type: "POST",
      url: template + "/ajax/list-email.php?post_temp=wer&l_email="+l_email+"&nocache=gio",
      data: "",
	  
      success: function(msg){
	    $('.list-email').attr("value","");
	    $(".send-notifer").html('Sent!').fadeIn().delay(3000).fadeOut(2000);
      }
    });
	
	};
    });


});


//end of ----------

function update() {
  //var Current = $('#manifesto-slides li').hide().removeClass('on');
  Current.next().fadeIn().addClass('on');
  //if(!Current.length){ alert("No element found!"); }

  window.setTimeout(update, 5000);
}

$(document).ready(function(){
  $('.gbslider li:first').show().addClass('on');
  update();
});
