var ANIMATION2 = 'easeOutBounce';
var ANIMATION = 'easeOutBack';

var SLIDE_DELAY = 3000;
var isiPad = navigator.userAgent.match(/iPad/i) != null;
// For use within iPad developer UIWebView
var ua = navigator.userAgent;
isiPad = /iPad/i.test(ua) || /iPhone OS 3_1_2/i.test(ua) || /iPhone OS 3_2_2/i.test(ua);
var isiPhone = navigator.userAgent.match(/iPhone/i) != null;
var isMAC = navigator.userAgent.match(/mac/i) != null;
var sPath = window.location.pathname;

var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
$(document).ready(function(){
if (navigator.appName == 'Microsoft Internet Explorer')
  {
    $(".menu").css( "width","+=200" );
	$(".menu").css( "left","-=40" );
    Cufon.replace(".link1");Cufon.replace(".link2");Cufon.replace(".link3");Cufon.replace(".link4");Cufon.replace(".link5");Cufon.replace(".link6");
	Cufon.replace(".jspPane h3");
	//alert( $(".menu").width())
	
  }
$(".fancybox").fancybox({
        'hideOnContentClick'    :    true,
        'speedIn'               :    600,
        'speedOut'              :    300,
        'overlayShow'           :    true,
        'padding'               :       0,
        'transitionIn'		: 'elastic',
	'transitionOut'		: 'elastic'

    });
$(function()
{
    if(sPage!="contact-us.php"){
	$('.left-body').jScrollPane();
    }
});


var win_width=$(window).width();
var width=(win_width-2054)/2;
$(".wrapper").css({left:width+"px"});



 if(sPage=="index.php" || sPage==""){
 $(".tenta").delay(800).animate({marginTop:-530+"px"},1600,ANIMATION2,function(){
   $(".logo").fadeIn(300)  ;
   $(".footer").css({marginLeft:-146+"px"});
   $(".madam-start").fadeOut(300,function(){
       $(".content-body").fadeIn(300,function(){ $(".video").fadeIn(300,function(){$(".madam").fadeIn(300,function(){
       $(".menu").fadeIn(300,function(){  $(".footer").fadeIn(300,function(){  $(".right-menu").fadeIn(300);});});
       });});});
       //$(".logo").fadeIn(1000);    
     
       
   });
   
 });
 }
 else{
 //$(".tenta").delay(1200).animate({marginTop:-530+"px"},0,ANIMATION2,function()
 $(".footer").css({left:30+"px"});
 $(".footer-6").css({left:1120+"px"});
 $(".logo").fadeIn(300,function(){
   $(".tenta").css({marginTop:-530+"px"});
   $(".madam-start").fadeOut(800,function(){
       $(".content-body").fadeIn(300,function(){ $(".right-menu").fadeIn(300,function(){$(".madam").fadeIn(300,function(){
       $(".menu").fadeIn(300,function(){  $(".footer").fadeIn(300,function(){  $(".video").fadeIn(300);});});
       });});});
       //$(".logo").fadeIn(1000);


   });

 });
 }
 menu_links();
 
 projectSlide();
    $(".footer-1").hover(
        function() {
           $(this).css({'background-image' : 'url("./images/kafasi-adio-b.png")','cursor':'pointer'});    
           } , function() {
             $(this).css({'background-image' : 'url("./images/kafasi-adio.png")'});    
        }
    );
	    $(".footer-11").hover(
        function() {
           $(this).css({'background-image' : 'url("./images/kiku-link-b.png")','cursor':'pointer'});    
           } , function() {
             $(this).css({'background-image' : 'url("./images/kiku-link.png")'});    
        }
    );
          $(".footer-2").hover(
        function() {
           $(this).css({'background-image' : 'url("./images/milo-b.png")','cursor':'pointer'});    
           } , function() {
             $(this).css({'background-image' : 'url("./images/milo.png")'});    
        }
    );
                $(".footer-3").hover(
        function() {
           $(this).css({'background-image' : 'url("./images/plastis-b.png")','cursor':'pointer'});    
           } , function() {
             $(this).css({'background-image' : 'url("./images/plastis.png")'});    
        }
    );

        $(".footer-4").hover(
        function() {
           $(this).css({'background-image' : 'url("./images/igia-b.png")','cursor':'pointer','z-index':'100'});    
           } , function() {
             $(this).css({'background-image' : 'url("./images/igia.png")'});    
        }
    );
        $(".footer-5").hover(
        function() {
           $(this).css({'background-image' : 'url("./images/kafasi-kapelo-b.png")','cursor':'pointer'});    
           } , function() {
             $(this).css({'background-image' : 'url("./images/kafasi-kapelo.png")'});    
        }
    );
        $(".footer-6").hover(
        function() {
           $(this).css({'background-image' : 'url("./images/letter-box-b.png")','cursor':'pointer'});    
           } , function() {
             $(this).css({'background-image' : 'url("./images/letter-box.png")'});    
        }
    );

$(".logo-link").live("click",function(){
       $(".madam").fadeOut(300);
       $(".right-menu").fadeOut(300);
       $(".footer").fadeOut(300);
       $(".video").fadeOut(300);
       $(".menu").fadeOut(300);
        $(".content-body").fadeOut(1000);
  $(".tenta").delay(2000).animate({marginTop:0+"px"},1200,ANIMATION2,function(){
     
     window.location = "index.php"; 
  }); 
});
//$(".logo-link").live("click",function(){
//       $(".madam").fadeOut(600,function(){
//          $(".right-menu").fadeOut(600,function(){
//            $(".footer").fadeOut(600,function(){
//              $(".menu").fadeOut(600,function(){
//                  $(".video").fadeOut(600,function(){
//                    $(".content-body").fadeOut(600,function(){
//                        $(".tenta").delay(2000).animate({marginTop:0+"px"},1600,ANIMATION2,function(){
//     
//     window.location = "index.html"; 
//  }); 
//                    });  
//                  });
//              });  
//            });  
//          }); 
//       });       
//       
//       
//       
//       
//          
//  
//});
$('.rec_img').click(function() {
var $thisLink = $(this).attr('id');

     $.ajax({
              url: "ajax.load.recipies.php",
              data:{story_id:$thisLink},
              type: "GET",
              success: function(data){ 
             $('div.recipies-body').fadeOut(1).html(data).fadeIn(200,function(){$('.left-body').jScrollPane();});

             
$(".fancybox").fancybox({
        'hideOnContentClick'    :    true,
        'speedIn'               :    600,
        'speedOut'              :    300,
        'overlayShow'           :    true,
        'padding'               :       0,
        'transitionIn'		: 'elastic',
	'transitionOut'		: 'elastic'

    });
 }
});

});
$('.news_link').click(function() {
   
var $thisLink = $(this).attr('id');

     $.ajax({
              url: "ajax.load.news.php",
              data:{story_id:$thisLink},
              type: "GET",
              success: function(data){
             $('div.left-body').fadeOut(1).html(data).fadeIn(200,function(){$('.left-body').jScrollPane();});
             

$(".fancybox").fancybox({
        'hideOnContentClick'    :    true,
        'speedIn'               :    600,
        'speedOut'              :    300,
        'overlayShow'           :    true,
        'padding'               :       0,
        'transitionIn'		: 'elastic',
	'transitionOut'		: 'elastic'

    });
 }
});

});
});
//$(document).load(function(){
//   document.location.href = document.location.href + "#";
//   setInterval(function(){
//      if (window.location.hash != '#')
//         document.location.href = document.location.href + "#";
//   }, 100);
//});
$(window).resize(function() {
  var win_width=$(window).width();
  var width=(win_width-2054)/2;
  //console.log(width);
  $(".wrapper").css({left:width+"px"});
  $(function()
{
	$('.left-body').jScrollPane();
});
  
});
function menu_links(){
    $(".menu-link").live("click",function(){
        var link_name=$(this).attr("name");
		if (link_name=='kiku-link'){
		$(".tenta").delay(1000).animate({marginTop:-530+"px"},0,ANIMATION2,function(){
		window.open('http://beta.kiku.it/en/Home','_blank' );
		});


		}
		else{
//        $(".madam").fadeOut(1000);
//       $(".right-menu").fadeOut(1000);
//       $(".footer").fadeOut(1000);
//       $(".video").fadeOut(1000);
//       $(".menu").fadeOut(1000);
//       $(".content-body").fadeOut(1000);
  $(".tenta").delay(1000).animate({marginTop:-530+"px"},0,ANIMATION2,function(){
     window.location = link_name+".php"; 
  }); }
    });
}
function moveSlider(currentIndex){
    alert(currentIndex);
    //$(".recipies-list").stop(true,true).animate({marginLeft:-(248*Index)},600);
}
function projectSlide(){
    var totalImages = $('.recipies-list').children('li').length;
 
    var currentIndex = 0;

    $(".right-arrow a").click(function(){
        if(currentIndex < totalImages-1){
            currentIndex++;
        } else {
            currentIndex = 0;
        }
        //alert(currentIndex);
       $(".recipies-list").stop(true,true).animate({marginLeft:-(248*currentIndex)+10},600);
    });

    $(".left-arrow a").click(function(){
        if(currentIndex > 0){
            currentIndex--;
        } else {
            currentIndex = totalImages-1;
        }
        //alert(currentIndex);
       $(".recipies-list").stop(true,true).animate({marginLeft:-(248*currentIndex)+10},600);
    });
}



function photoSlideHover(){

    $(".main-menu li a, .slider-menu-links li a").hover(
        function() {
            $(this).parent().css({'z-index' : '5'}); /*Add a higher z-index value so this image stays on top*/
            $(this).children('img').addClass("hover").stop() /* Add class of "hover", then stop animation queue buildup*/
                .animate({
                        top: '-15px',
                        left: '-25px',
                       
                        width: '150px', /* Set new width */
                        height: '100px'
                       /* Set new height */
                }, 210); /* this value of "200" is the speed of how fast/slow this hover animates */
        } , function() {
            $(this).children('img').stop()  /* Remove the "hover" class , then stop animation queue buildup*/
                .animate({
                        top: '0',
                        left: '0',
                        width: '125px', /* Set width back to default */
                        height: '85px' /* Set height back to default */
                }, 200,function(){
                    $(this).removeClass("hover");
                    $(this).parent("a").parent().css({'z-index' : '2'}); /* Set z-index back to 2 */
                });
        }
    );
} 
function photoSlideHover2(){

    $(".ing-div").hover(
        function() {
            $(this).parent().css({'z-index' : '5'}); /*Add a higher z-index value so this image stays on top*/
            $(this).children('img.first').addClass("hover").stop() /* Add class of "hover", then stop animation queue buildup*/
                .animate({
                        left: '-30px',
                        top:'-30px',
                        width: '168px', /* Set new width */
                        height: '168px'
                        
                       /* Set new height */
                }, 210); /* this value of "200" is the speed of how fast/slow this hover animates */
        } , function() {
            $(this).children('img.first').stop()  /* Remove the "hover" class , then stop animation queue buildup*/
                .animate({
                        top: '0',
                        left: '0',
                        width: '108px', /* Set width back to default */
                        height: '108px' /* Set height back to default */
                }, 200,function(){
                    $(this).removeClass("hover");
                    $(this).parent("a").parent().css({'z-index' : '2'}); /* Set z-index back to 2 */
                });
        }
    );
} 
function menu_close(){
    $('a.home-link-close').click(function(){
    $(".products-container2").slideUp(300,function(){$('.grey-area').css({display:"none"})});
    $("#expand").click();    
});
}
function SlidePanels(){
  
    $('#left-button-js').click(function(){
        
        moveSlider(0);
    });

    $('#right-button-js').click(function(){
       
        moveSlider(-1920);
    });
     $('#1right-button-js').click(function(){
       
        moveSlider(-960);
    });
    $('#2left-button-js').click(function(){
       
        moveSlider(-960);
    });
}

function moveSlider(index){
    $('.slideshow').stop(true,true).animate({marginLeft:index+"px"},700);
    
} 

function runSlideMenuAnimation(){
   
    var bodyScrollTop;
    var BodyScrollHeight=($(window).height()/2)-250;
    var BodyWidth=$(window).width();
   
    var rightV=(BodyWidth-960)/2;
    
    
    if(isiPad || isiPhone){
        bodyScrollTop = $('body').scrollTop();
    }
    else{
        bodyScrollTop = $(window).scrollTop();
    }
   
  //$('#menu-slide').stop(true,true).animate({top: bodyScrollTop+BodyScrollHeight+"px"},600);
  if(bodyScrollTop>=$('#home-page').height()){

$('#menu-slide').stop(true,false).animate({top:bodyScrollTop+BodyScrollHeight+"px",right:rightV-100},2000);

}
else{
 $('#menu-slide').stop(true,false).animate({top:$('#home-page').height()+4+"px",right:rightV-99},200);   
}

          
}

function SlideMenu(){
    
    runSlideMenuAnimation(); 
    $(window).scroll(function () {
        runSlideMenuAnimation();
    });

    $(window).resize(function () {
        runSlideMenuAnimation();
    });
}

function projectSlide2(slide_index,right_handler,left_handler){
    var totalImages = $('.'+slide_index).children('li.fancyboxItem').length;
    
    var currentIndex = 0;

    $('.'+right_handler+' a').click(function(){
        if(currentIndex < totalImages-1){
            currentIndex++;
        } else {
            currentIndex = 0;
        }
        //alert(currentIndex);
        moveSlider2(currentIndex,slide_index);
    });

    $('.'+left_handler+' a').click(function(){
        if(currentIndex > 0){
            currentIndex--;
        } else {
            currentIndex = totalImages-1;
        }
        moveSlider2(currentIndex,slide_index);
    });
}

function moveSlider2(Index,slide_index){
    //alert(slide_index);
    $('.'+slide_index).stop(true,true).animate({marginLeft:-(490*Index)},600);
}
function moveSlider3(Index,slide_index2){
    //alert(slide_index);
    $('#'+slide_index2).stop(true,true).animate({marginLeft:-(440*Index)},600);
}

function MenuClick(){
    $("#expand").unbind("click").toggle(
    function(){
        $('.grey-area').css({display:"block"});
        $(".products-container2").slideDown(400);
    },
    function(){
        
        $(".products-container2").slideUp(300,function(){
            $('.grey-area').css({display:"none"})
           
        });
    });

}

function showBottomArea(){
    
    var top_area_height = $('#home-page').height();
    $('#wrapper').css({top:top_area_height});
    
    $('.main-menu li a').click(function(){
     var nameval=$(this).attr("name");
     var targetOffset = $('.'+nameval).offset().top; 
     
     $('html,body').animate({scrollTop: targetOffset}, SLIDE_DELAY,ANIMATION);
 });
   
      
   
    
}
function showBottomArea2(){
    
// var top_area_height = $('#home-page').height();
//    $('#wrapper').css({top:top_area_height});
    
    $('.products-container2 ul li a').live("click",function(){
    var nameval=$(this).attr("name");
     
     var targetOffset = $('.'+nameval).offset().top; 
     $("#expand").click();
      $('html,body').animate({scrollTop: targetOffset}, SLIDE_DELAY,ANIMATION,
     
     $('.grey-area').css({display:"none"})    
    );
    
 
return false;
    });
    
}

function showBottomArea3(menuIndex){

    $('.'+menuIndex+' ul li a').live("click",function(){
        
    
    var nameval=$(this).attr("name");
      
     var targetOffset = $('.'+nameval).offset().top; 
    
      $('html,body').animate({scrollTop: targetOffset}, SLIDE_DELAY,ANIMATION);
    });
  
  

}

function showMainPage(){
    
    $('.menu-logo a').live("click",function(){
    var nameval=$(this).attr("name");
     //alert(nameval);
     var targetOffset = $('.'+nameval).offset().top; 
     $("#expand").click();
      $('html,body').animate({scrollTop: targetOffset}, 
      {
      
    duration:2000,
    specialEasing: {
      width: 'linear',
      height: 'easeOutBounce'
    }            
                
            },
     $('.grey-area').css({display:"none"})    
    );
    
 
return false;
    });
    
}



function CheckValidMail(email,name){
    if(email!=""){
        var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,4}$/;
        if(emailPattern.test(email)){
            $('input[name="'+name+'"]').css('border','1px solid #DEDEDE');
            return true;
        }
        else{
            $('input[name="'+name+'"]').css('border','1px solid yellow');
            display_message+='<div>'+$('#error_hidden_valid_email').val()+'</div>';
            return false;
        }
    }
    else{
        return false;
    }
    
}
function CheckInputNotNull(element,element_name){
    if(element!="" && element!="undefined" ){
        $('input[name='+element_name+']').css('border','1px solid #DEDEDE');
        return true;
    }
    else{
        $('input[name='+element_name+']').css('border','1px solid yellow');
        display_message+='<div>'+$('#error_hidden_'+element_name).val()+'</div>';
        return false;
    }
}

function registerContact(){
    //alert(1);
    $('.message').empty().slideUp(300);
    var passed = true;
    display_message = "";
    var name = $('#contact_name').val();
    var surname = $('#contact_surname').val();
    var email = $('#contact_email').val();
    
    
    var comments = $('#contact_comments').val();
    //alert (comments);
    
    
    if(!CheckInputNotNull(name,"name"))
        passed = false;
     if(!CheckInputNotNull(surname,"surname"))
        passed = false;
    if(!CheckInputNotNull(email,"email"))
        passed = false;
    if(!CheckValidMail(email,"email"))
        passed = false;
    if(!CheckInputNotNull(comments,"comments"))
        passed = false;
    //send form
        if(passed){
            display_message = "<div>Sending...</div>";
            $('.message').html(display_message).fadeIn(600);
            $.post('/send.contact.php' , {name:name,surname:surname,email:email, comments:comments}, function(data) {
                $('.message').html(data).fadeIn(600);
                ClearForm();
            });
        }
        else{
            $('.message').html(display_message).slideDown(800);
        }
}
function registerContactDE(){
    //alert(1);
    $('.message').empty().slideUp(300);
    var passed = true;
    display_message = "";
    var name = $('#contact_name').val();
    var surname = $('#contact_surname').val();
    var email = $('#contact_email').val();
    
    
    var comments = $('#contact_comments').val();
    //alert (comments);
    
    
    if(!CheckInputNotNull(name,"name"))
        passed = false;
     if(!CheckInputNotNull(surname,"surname"))
        passed = false;
    if(!CheckInputNotNull(email,"email"))
        passed = false;
    if(!CheckValidMail(email,"email"))
        passed = false;
    if(!CheckInputNotNull(comments,"comments"))
        passed = false;
    //send form
        if(passed){
            display_message = "<div>Senden...</div>";
            $('.message').html(display_message).fadeIn(600);
            $.post('/send.contactDE.php' , {name:name,surname:surname,email:email, comments:comments}, function(data) {
                $('.message').html(data).fadeIn(600);
                ClearForm();
            });
        }
        else{
            $('.message').html(display_message).slideDown(800);
        }
}
function ClearForm(){
  $('.formItem input,.formItem textarea').val('');
}


