
/* -----------------------------------------------
js for cateristic (c) tim kaiser 2011 freemee.de 
----------------------------------------------- */


//var BASE = "/preview11";  // DEV
var BASE = "";          // PRODUCTIVE


// set iPhone COOKIE for full site view
$(document).ready(function(){  
    $(".fullsite").click(function(){ 
        $.cookie("MobileCateristic", "show-full-site");
    });
});




$(document).ready(function(){ 

     if ($('#slideshow') && ($('#slideshow').children().length == 1)) {$('#slideshow:first').show();}
    
    // iam sorry, but no rightklicks…
    $("body").noContext();

    $('#slideshow img:first').fadeIn(0, function() { //fade in first slows down the ajax!!       
        $('#slideshow').cycle({ 
              before:       onBefore,
              delay:        100,         
              fx:           'fade', 
              easing:       "easeOutCirc", 
              speed:        1550,
              timeout:      8000, 
              next:         '#next',
              prev:         '#prev',
              fastOnEvent:  100,
              after:        onAfter
        });
    });
}); 

// the before
function onBefore() {     
    // split img source to array
    var schring = this.src;
    var element = schring.split("/"); 
    
    $.ajax({
                cache:      "true",
                type:       "GET",
                dataType:   ($.browser.msie) ? "text" : "html", 
                url:        BASE + '/functions/subnavi.php', 
                data:       "kat="+element[5]+"&skat="+element[6]+"&lang="+lang,
                //async:      true,
                complete:   function (debug){$('#debug p').html("√ complete");$('.'+element[6]).css('color', '#7f3589');},//DEBUG ONLY
                success:    function(msg){$('#subnavi').html(msg);}
                
    });
    
    // output image title
    $('#output').html(this.alt);
    $('.navi').css('color', '#666');
    $('.'+lang).css('color', '#7f3589').css('fontWeight', 'bold');
    $('.'+element[5]).css('color', '#7f3589');
    $('.'+element[7]).css('color', '#7f3589').css('fontWeight', 'bold');
}

//the after
function onAfter() {     
    $('#controlalert').fadeOut(500);
}


// the fullscreener
$(document).ready(function($) {

  var hi =  $(window).height();
  var wi =  $(window).width();

  if ( hi > wi/1.6){    
          $("#slideshow").css("height", hi); 
          $("#slideshow").css("width", hi*1.6);
          $("#slideshow").css("top", -wi/100);
  }else{
          $("#slideshow").css("top", -wi/100*2.5);
          $("#slideshow").css("width", wi);
          $("#slideshow").css("height", wi/1.6); 
  }

  $(window).resize(function() { 
  
          var hi =  $(window).height();
          var wi =  $(window).width();
  
          if ( hi > wi/1.6){
                $("#slideshow").css("height", hi); 
                $("#slideshow").css("width", hi*1.6);
          }else{
                $("#slideshow").css("width", wi);
                $("#slideshow").css("height", wi/1.6);
          }
          if ( hi > wi/1.6){}
  });
});


// Logo -> Home
$(document).ready(function(){ 
      $("#logo").click(function(){ 
          top.location="http://cateristic.com"+BASE}); 
});




$(document).ready(function() {
    //some subnavigation verhalten
    $('.headtoggle').click(function() {
        $('#subnavi').animate({height: ['toggle', 'easeInCirc']}, 100);
        $('#navidescription-box').hide(100);
        $('#subnavidescription-box').hide(100);
        $(".headtoggle").toggle();  // switch up and down button    
    });    
    // order button - form expand
    $('#order-button').click(function() {
        $('#order-form').animate({height: ['toggle', 'easeInCirc']}, 100);
        $('#order-button').fadeOut(100);
        $('#subnavidescription-box').animate({height: ['toggle', 'easeInCirc']}, 100);   
    });    
        
    var kat = $.getUrlVar('kat');
    if (kat != "") {
            $('#navidescription-box').delay(100).animate({height: ['toggle', 'swing']}, 70);
      }else{}
    
    $('#subnavidescription-box').animate({height: ['toggle', 'swing']}, 100);    
    $('#txtbox').fadeIn(0);                                              
    $('#subnavibox').fadeIn(0);                                            
    $('#order-button').delay(250).fadeIn(500);
});


//  the ajax contact form
$(document).ready(function() {
  $('#submitform').ajaxForm({
    target: '#error',
    success: function() {
      $('#error').fadeIn('slow');
    }
  });
});

// the big box contains, about, jobs, contact
$(document).ready(function() {
  
    $("#close").click(function() {
        $("#bigbox").animate({height:"100"}, {duration: 600, easing: 'easeInBack'});
        $('#bigbox').fadeOut('fast');
    });
     
       
    $('.bigbox').click(function() {    
        if ($("#bigbox").is(":hidden")) {
            $("#bigbox").animate({height:"600"}, {duration: 600, easing: 'easeOutBack'});
        }    
         
    var boxID = this.id;
    
    $.ajax({
            cache:      "true",
            type:       "GET",
            dataType:   ($.browser.msie) ? "text" : "html", 
            url:        BASE +'/functions/bigbox.php', 
            data:       "lang="+lang+"&bigbox="+boxID,
            async:      true,
            success:    function(msg){$('#bbox-container').html(msg);}
      });
    });  
});


// play pause feedback slideshow
$(function() {
    $('#slideshow').toggle(function() { 
        $('#slideshow').cycle('pause'); 
        $('#controlalert').fadeIn('fast').html('II').fadeOut(1200);
    }, 
    function() { 
        $('#slideshow').cycle('resume', false); 
        $('#controlalert').fadeIn('fast').html('>').fadeOut(1200);
    }); 
});


// tastensteuer
$(document).keydown(function (e) {      
      if (e.which == 39) {
          $("#next").trigger('click');
          $('#controlalert').show(0).html('&raquo;');
      }       
      if (e.which == 37) {
          $("#prev").trigger('click');
          $('#controlalert').fadeIn(0).html('&laquo;');
      }
});


// dont need this anymore!!
//get url vars via jquery / needed for the language parameters while the ajay request

$.extend({
  getUrlVars: function(){
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
      hash = hashes[i].split('=');
      vars.push(hash[0]);
      vars[hash[0]] = hash[1];
    }
    return vars;
  },
  getUrlVar: function(name){
    return $.getUrlVars()[name];
  }
});


//HOWTO GET EM

// Get object of URL parameters
//var allVars = $.getUrlVars();

// Getting URL var by its nam
//var byName = $.getUrlVar('name');


/* check consistancy of Email */
function EMail(s){
     var a = false;
     var res = false;
     if(typeof(RegExp) == 'function') {
       var b = new RegExp('abc');
       if(b.test('abc') == true){a = true;}
    }

     if(a == true)
     {
      reg = new RegExp('^([a-zA-Z0-9\\-\\.\\_]+)'+
                       '(\\@)([a-zA-Z0-9\\-\\.]+)'+
                       '(\\.)([a-zA-Z]{2,4})$');
      res = (reg.test(s));
     }
     else
     {
      res = (s.search('@') >= 1 &&
             s.lastIndexOf('.') > s.search('@') &&
             s.lastIndexOf('.') >= s.length-5)
     }
     return(res);
}


/* Ajax jobs, request and contact form validation and subscription  */
function sendForm(selectWhichForm, output){
            $.ajax({
                //cache:      "true",
                //dataType:   ($.browser.msie) ? "text" : "html", 
                type:       "POST",
                url:        BASE +'/aja/contact.php?lang='+lang, 
                data: $('#'+selectWhichForm).serialize(),
                async:      false,
                success:    function(msg){
                //console.log($('#'+selectWhichForm).serialize());
                $('#'+output).html(msg);
                }
          });
  return false;
}

/*    ajaxFileUpload(); is a helping function inside the job form that does FILEUPLOADING 
      since regular $FILE upload does not work in a a ajaxed  enviromet */
function ajaxFileUpload(){
  
  $("#theImageUploadLoading")
  .ajaxStart(function(){
    $(this).show();
    $('#imageControlJobs').show();
    $('#klammer').css("visibility", "visible");
    
  })
  .ajaxComplete(function(){
    $(this).hide();
  });
  
  
  
  
  $.ajaxFileUpload ({
      url: BASE +'/aja/doajaxfileupload.php',
      secureuri:false,
      fileElementId:'fileToUpload',
      dataType: 'json',
      success: function (data, status){
        if(typeof(data.error) != 'undefined')
        {
          if(data.error != '')
          {
            alert(data.error);
            }else{
              /* writing the path of the uploaded image into a hidden field so we can work with the image */
              $('#imageURLJobs').val(data.msg);
              URL = data.msg;
              /* displaying the image */
              $('#imageControlJobs').html("<img id='theUploadedImage' src='"+BASE +"/aja/_apply/"+URL+"' alt='soúndso' width='100' />")
              $('#klammer').css("visibility", "visible");

            }
          }
      }
      /*,
      error: function (data, status, e) {
        alert(e);
      }
      */
    })

  return false;
}

// facebook link
$(document).ready(function(){ 
  $("#ficon").click(function(){ 
  window.open("http://www.facebook.com/pages/CATERISTIC/141853749162405", "facebook","menubar=0,resizable=1,width=1024,height=800")}); 
});



//trying to disable firefox scrolling








