/**************************/
/* LAYOUT STUFF        */
/**************************/

/* SYNC HEIGHTS OF DIVS CONTENT AND SIDEBAR */
$(document).ready(function(){
  $(".equalHeight").syncHeight();
  $(window).resize(function(){ //if you want to update the columns after a Browser resize (optional)
    $(".equalHeight").syncHeight();
  });
});

$(function() {     
  $("#main .content ul li").prepend("<i></i>");
  $("#blogMain .content ul li").prepend("<i></i>");
  /* $("ul.listItem li").prepend("<i></i>"); */
});


/* DYNAMICALLY ADD FLOAT:RIGHT TO ODD LAB BUBBLES */
$(document).ready(function() {
  $("div.labBubbles div:odd").css("float", "right");
});

/* DYNAMICALLY ADD FLOAT:RIGHT TO taloom Summer edition Images */
$(document).ready(function() {
  $("#seContent img:even").css("float", "left");
  $("#seContent img:odd").css("float", "right");
});

/**************************/
/* STAGES         */
/**************************/

/* SCROLLABLE STAGE CONTENT ON HOME PAGE */
$(function() {         
    // initialize scrollable  
    window.api = $("div.scrollable").scrollable({ 
        size: 1, 
        items: '#stages',
        loop: true,
        clickable: false
  }).navigator().autoscroll({
    autoplay: true,
    api: true,
    interval: 12000
  });      
});

/* TALOOM STAGE SWITCH */
$(function() { 
    $("#taloomNavi").tabs("#taloomSwitch > div", {
      event:'mouseover',
      rotate: true
    }).slideshow({
      autoplay:true,
      clickable:false
    }); 
});


/**************************/
/* NAVIGATION       */
/**************************/

/* SUBMENU EINBLENDEN BEI PARENT-SEITEN */
$(function(){
  //wenn container leer ist => ausblenden
  if($('#subNavi').length == 0) {
    $('#navigation').attr("id","navigationHalf");
  }
});

/* NAVIGATION FOOT - LOESUNGEN IN SITEMAP KOPIEREN */
$(function(){
  try{
    $('#nav-foot-no-4').append($('#sitemap_sol_container').html());
  }catch(e) {}
  try{
    $('#nav-foot-no-89').append($('#sitemap_sol_container').html());
  }catch(e) {}
});   

/* NAVIGATION HOVER BEI LOESUNGEN */
$(function() {
  $('#mouseOverHead').hide();
  $('#mouseOverBody').hide();
  
  try{
    //german
  $('#mainNavi li#navi-no-4 a').mouseover(function() {
      $('#mouseOverHead').fadeIn('fast');
      $('#mouseOverBody').fadeIn('fast');
      return false;
    });
} catch(e) {}
  
try{
  //english
  $('#mainNavi li#navi-no-89 a').mouseover(function() {
      $('#mouseOverHead').fadeIn('fast');
      $('#mouseOverBody').fadeIn('fast');
      return false;
    });
} catch(e) {}
  
    $('#mouseOverHead').hover(
    function() {
      $('#mouseOverHead').show();
      $('#mouseOverBody').show();
        },
        function() {
        $('#mouseOverHead').hide(); 
      $('#mouseOverBody').hide();     
      }
     );    
     $('#mouseOverBody').hover(
    function() {
      $('#mouseOverHead').show();
      $('#mouseOverBody').show();
        },
        function() {
        $('#mouseOverHead').hide(); 
      $('#mouseOverBody').hide();         
      }
     );
});

/* NAVIGATION HOVER ON SEARCH */
$(function() {
  $('#searchMouseOver').hide();
  $('#mainNavi li.search a').mouseover(function() {
      $('#searchMouseOver').fadeIn('fast');
      return false;
    });
    $('#searchMouseOver').hover(
    function() {
      $('#searchMouseOver').show();
      
        },
        function() {
        $('#searchMouseOver').fadeOut('slow');  
        }
     );
});

/* LOESUNGEN NAVI BIG BUTTONS */
$(function() { 
    $("#dashboardNavi").tabs("#dashboardContent > ul", {
      event:'click',
      effect:'fade',
      fadeInSpeed: 300,
      fadeOutSpeed: 0
    }); 
});

/* SMOOTH HOVER FADES */
$(document).ready(function() {
  $('#dashboardContent li a').append('<span class="hover"></span>').each(function () {
      var $span = $('span.hover', this).css('opacity', 0);
      $(this).hover(function () {
        $span.stop().fadeTo(300, 1); //Change the number 500 to change the speed of the Fade In
     }, function () {
     $span.stop().fadeTo(500, 0); //Change the number 500 to change the speed of the Fade Out
      });
  });
});
  
$(document).ready(function() {
  $('#mouseOverBody li a').append('<span class="hover"></span>').each(function () {
      var $span2 = $('span.hover', this).css('opacity', 0);
      $(this).hover(function () {
        $span2.stop().fadeTo(300, 1); //Change the number 500 to change the speed of the Fade In
     }, function () {
     $span2.stop().fadeTo(500, 0); //Change the number 500 to change the speed of the Fade Out
      });
  });
});


/**************************/
/* FEATUREBOXEN       */
/**************************/

/* FEATURE TABS */
$(function() { 
    $("#featurebox ul.tabs").tabs("#featurebox div.panes > div", {
      event:'click',
      effect:'fade',
      fadeInSpeed: 300,
      fadeOutSpeed: 0
    }); 
});

/**************************/
/* FEATURES TALOOM SUMMER EDITION       */
/**************************/

/* FEATURE TABS */
/*
$(function() { 
    $("#seSidebar ul.tabs").tabs("#seContent > div", {
      effect: 'fade',
      event:'click',
      fadeInSpeed: 300,
      fadeOutSpeed: 0
    }); 
});
*/
$(function() { 
  $('#seSidebar ul.tabs a').each(
    function( noJump ){
        // Anhang des Anchors, damit die Seite beim Reload weniger springt
    var anchor = "#seNavi";
        var newHREF = $( this ).attr('href') + anchor;
        
    $( this ).attr('href', newHREF);
  });
  
  $('#seContent div a').each(
    function( noJump ){
        // Anhang des Anchors, damit die Seite beim Reload weniger springt
    var anchor = "#seNavi";
        var newHREF = $( this ).attr('href') + anchor;
        
    $( this ).attr('href', newHREF);
  });
});

/**************************/
/* BLOG            */
/**************************/

/* QUICKFINDER TABS BLOG HOME */
$(function() {
  $("#tabs").tabs("#panes > div");
});

/* REPLACE SELECTBOX FOR ARCHIVE */
$(function() {
  $("#archive").selectbox();
});

/**************************/
/* OVERLAYS          */
/**************************/

/* POSTIT OVERLAY */
$(document).ready(function() {
  $("#stage area[rel]").overlay({     
    top: 270,    
      // some expose tweaks suitable for modal dialogs 
      expose: { 
          color: '#333', 
          loadSpeed: 100, 
          opacity: 0.7 
      },    
      closeOnClick: false 
    });
});

/* ENABLE OVERLAY */
$(document).ready(function() {
  $("#dashboard area[rel]").overlay({ 
      // some expose tweaks suitable for modal dialogs 
      expose: { 
          color: '#333', 
          loadSpeed: 100, 
          opacity: 0.7 
      },
      closeOnClick: false 
    });
});

/* ENABLE OVERLAY */
$(document).ready(function() {
  $("a.overlay[rel]").overlay({ 
      // some expose tweaks suitable for modal dialogs 
      expose: { 
          color: '#333', 
          loadSpeed: 100, 
          opacity: 0.7 
      }, 
   
      closeOnClick: false
    });
});

/* ENABLE OVERLAY */
$(document).ready(function() {
  $("a.overlayTaloom[rel]").overlay({ 
      // some expose tweaks suitable for modal dialogs 
      expose: { 
          color: '#333', 
          loadSpeed: 100, 
          opacity: 0.7 
      }, 
     top: '30%',
      closeOnClick: false
    });
});

/* ENABLE OVERLAY 
$(document).ready(function() {
  $("a.contactButton[rel]").overlay({ 
      // some expose tweaks suitable for modal dialogs 
      expose: { 
          color: '#333', 
          loadSpeed: 100, 
          opacity: 0.7 
      }, 
   
      closeOnClick: false
    });
});
*/

/* SLIMBOX FOR LINKED IMAGES */
$(document).ready(function(){  
  var select = $('a[href$=".bmp"], a[href$=".gif"], a[href$=".jpg"], a[href$=".jpeg"], a[href$=".png"], a[href$=".BMP"], a[href$=".GIF"], a[href$=".JPG"], a[href$=".JPEG"], a[href$=".PNG"]');
  select.slimbox({
    overlayOpacity: 0.7,
    loop: true,
    overlayFadeDuration: 100,
    captionAnimationDuration: 100,
    resizeDuration: 400,
    counterText: "Bild {x} von {y}"
  });
});


/**************************/
/* VALIDATION          */
/**************************/

/* COMMENT FORM VALIDATION */
$(function() {
  var errorContainer = $("<div class='error'>Bitte die Pflichtfelder ausf&uuml;llen.</div>").appendTo("#commentform").hide();
  var errorLabelContainer = $("<div class='error errorlabels'></div>").appendTo("#commentform").hide();
  $("#commentform").validate({
    rules: {
      author: "required",
      email: {
        required: true,
        email: true
      },
      url: "url",
      comment: "required"
    },
    errorContainer: errorContainer,
    errorLabelContainer: errorLabelContainer,
    ignore: ":hidden"
  });
  $.validator.messages.required = "";
  $.validator.messages.email = "Bitte eine g&uuml;ltige Email Adresse angeben.";
  $.validator.messages.url = "Bitte die URL mit &laquo;http://&raquo; angeben";
});

/* SALESFORCE CONTACT FORM VALIDATION */
$(function() {
  var errorContainer = $("<div class='error'>Bitte die Pflichtfelder ausf&uuml;llen.</div>").appendTo(".errormsg").hide();
  var errorLabelContainer = $("<div class='error errorlabels'></div>").appendTo(".salesforce").hide();
  $(".salesforce").validate({
    rules: {
      first_name: "required",
      last_name: "required",
      email: {
        required: true,
        email: true
      },
      description: "required",
      phone: "required"
    },
    errorContainer: errorContainer,
    errorLabelContainer: errorLabelContainer,
    ignore: ":hidden"
  });
  $.validator.messages.required = "";
  $.validator.messages.email = "Bitte eine g&uuml;ltige Email Adresse angeben.";
});

/* DOWNLOAD FORM VALIDATION (SF) */
$(function() {
  var errorContainer = $("<div class='error'>Bitte die Pflichtfelder ausf&uuml;llen.</div>").appendTo(".errormsg").hide();
  var errorLabelContainer = $("<div class='error errorlabels'></div>").appendTo(".salesforce").hide();
  $(".sfdownload").validate({
    rules: {
      first_name: "required",
      last_name: "required",
      company: "required",
      email: {
        required: true,
        email: true
      }
    },
    errorContainer: errorContainer,
    errorLabelContainer: errorLabelContainer,
    ignore: ":hidden",
    submitHandler: function(form) {
      jQuery.cookie("userdataGiven", "true", { expires: 3 });
      form.submit();
   }
  });
  $.validator.messages.required = "";
  $.validator.messages.email = "Bitte eine g&uuml;ltige Email Adresse angeben.";
});

/* SALESFORCE CONTACT FORM VALIDATION EN*/
$(function() {
  var errorContainer = $("<div class='error'>Please fill in the required fields.</div>").appendTo(".errormsg").hide();
  var errorLabelContainer = $("<div class='error errorlabels'></div>").appendTo(".salesforce_en").hide();
  $(".salesforce_en").validate({
    rules: {
      first_name: "required",
      last_name: "required",
      email: {
        required: true,
        email: true
      },
      phone: "required",
      description: "required"
    },
    errorContainer: errorContainer,
    errorLabelContainer: errorLabelContainer,
    ignore: ":hidden"
  });
  $.validator.messages.required = "";
  $.validator.messages.email = "Please enter a valid e-mail address.";
});

/**************************/
/* taloom SE 2010 LINK    */
/**************************/

$(document).ready(function(){
  $("#taloomSE2010").hover(
    function() {
      $(this).animate({"left": "-150px"}, "fast", "swing");
    },
    function() {
      $(this).animate({"left": "-58px"}, "fast", "swing");
    }
  );
});

/************************/
/*  Download Popup      */
/************************/

function showDownloadPopup(event){
  var popup = $('#downloadPopup'); 
  var submit = popup.find('input.retURL'); 
  var requestedDownload = popup.find('input.requestedDownload');
  var skip = popup.find('a.skipLink');
  
  var downloadPrefix = '';
  if(event.data.url.match('^http.*') == null) {
    downloadPrefix = 'http://www.softgarden.de/';
  }
  submit.attr('value', 'http://www.softgarden.de/index.php?id=145&url=' + escape(downloadPrefix + event.data.url));
  requestedDownload.attr('value', event.data.url);
  skip.attr('href', event.data.url); skip.click(hideDownloadPopup);
  var topMargin = event.pageY - 250;
  popup.css('top', topMargin > 50 ? topMargin : 50 );
  popup.show();
  $('#overlay_bg').show();
}

function hideDownloadPopup() {
  $('#downloadPopup').hide();
  $('#overlay_bg').hide()
}

function blurDownload(){
  var links = $('a.download');
  links.each(function(){
    var src = $(this).attr('href');
    $(this).attr('href','javascript:void(0)');
    $(this).bind('click', {url: src}, showDownloadPopup);
  });
}

$(document).ready(function(){
  if(jQuery.cookie('userdataGiven') == null)
  {
    var popup = $('#downloadPopup');
    popup.find('.close').bind('click', hideDownloadPopup);
    blurDownload();
    $('body').append('<div id="overlay_bg" style="display: none; position: absolute; z-index: 9999; top:0px; left: 0px; background-color: black; opacity: 0.5; filter:alpha(opacity=50); width: 100%; height:'+ $(document).height() +'px"></div>');
  }
});

