jQuery.fn.DefaultValue = function(text){
    return this.each(function(){
    //Make sure we're dealing with text-based form fields
    if(this.type != 'text' && this.type != 'password' && this.type != 'textarea')
      return;
    
    //Store field reference
    var fld_current=this;
    
    //Set value initially if none are specified
        if(this.value=='') {
      this.value=text;
    } else {
      //Other value exists - ignore
      return;
    }
    
    //Remove values on focus
    $(this).focus(function() {
      if(this.value==text || this.value=='')
        this.value='';
    });
    
    //Place values back on blur
    $(this).blur(function() {
      if(this.value==text || this.value=='')
        this.value=text;
    });
    
    //Capture parent form submission
    //Remove field values that are still default
    $(this).parents("form").each(function() {
      //Bind parent form submit
      $(this).submit(function() {
        if(fld_current.value==text) {
          fld_current.value='';
        }
      });
    });
    });
};

function setBackground() {
  var myClass = $("#container").attr("class");

  switch (myClass) {
    case "home":
      $.supersized({
        slides : [{
          image : 'fileadmin/templates/img/bg/bg_home.jpg'
        }]
      });
      break;
    case "denim":
      $.supersized({
        slides : [{
          image : 'fileadmin/templates/img/bg/bg_alberto.jpg'
        }]
      });
      break;
    case "collection_ss12":
      $.supersized({
        slides : [{
          image : 'fileadmin/templates/img/bg/alberto_fs12_background.jpg'
        }]
      });
      break;
    case "golf":
      $.supersized({
        slides : [{
          image : 'fileadmin/templates/img/bg/bg_golf.jpg'
        }]
      });
      break;
    case "golf golf12":
      $.supersized({
        slides : [{
          image : 'fileadmin/templates/img/bg/albertoGolf_fs12_background.jpg'
        }]
      });
      break;
    case "alberto":
      $.supersized({
        slides : [{
          image : 'fileadmin/templates/img/bg/bg_A.png'
        }]
      });
      break;
    default:
/*
      $.supersized({
        slides : [{
          image : 'fileadmin/templates/img/bg/bg.jpg'
        }]
      });
*/
      break;
  }
}

function getMaxHeight() {
  var availHeight = 0;

  if(document.layers) {
    availHeight = window.innerHeight + window.pageYOffset;
  } else if(document.all) {
    availHeight = document.documentElement.clientHeight + document.documentElement.scrollTop;
  } else if(document.getElementById) {
    availHeight = window.innerHeight + window.pageYOffset;
  }
  return availHeight;
}

function getMaxWidth() {
  var availWidth = 0;

  if(document.layers) {
    availWidth = window.innerWidth + window.pageXOffset;
  } else if(document.all) {
    availWidth = document.documentElement.clientWidth + document.documentElement.scrollLeft;
  } else if(document.getElementById) {
    availWidth = window.innerWidth + window.pageXOffset;
  }
  return availWidth;
}

function isiPhone(){
  return (
    //Detect iPhone
    (navigator.platform.indexOf("iPhone") != -1) ||
    //Detect iPod
    (navigator.platform.indexOf("iPod") != -1)
  );
}


function resizeCollection() {
  var maxHeight = getMaxHeight();
  var maxWidth = getMaxWidth();
  maxHeight = maxHeight - 145;
  maxWidth = maxWidth - 700;
  if (maxWidth < 420) maxWidth = 420;
  if (maxHeight < 440) maxHeight = 440;
  
  collectionWidth = parseInt(maxHeight * 0.74);
  if (collectionWidth > maxWidth) {
    collectionWidth = maxWidth;
    collectionHeight = parseInt(collectionWidth * 1.34);
  } else {
    collectionHeight = maxHeight;
  }
  
  tw = parseInt((collectionWidth - 12 * 4 - 50) / 12);
  th = parseInt(tw * 1.34);
  
  $('#collection-container').height(collectionHeight);
  $('#collection-container').width(collectionWidth);
  $("#gallery-img-fullsize img").height(collectionHeight);
  $("#gallery-img-fullsize img").width(collectionWidth);
  
  $('.thumb-image').height(th);
  $('.thumb-image').width(tw);
}

var collectionWidth = 0;
var collectionHeight = 0;

$(document).ready(function() {
  setBackground();
  resizeCollection();
  $('a.lightbox').fancybox({padding: 0}); 
  $('a.lightbox-iframe').fancybox({
    padding: 0,
    width: '60%',
    height: '75%',
    type: 'iframe'
    
  });
  $('.lightbox-video').fancybox({
          padding: 0,
          onStart: function() {
            if (video) { 
              $('#video-container').html(video);
            } else {
              $('#video-container').html(html5Video);
            }
          },
          onCleanup: function() {
            if (video) { 
              $('#video-container').flash().remove();
            } else {
              $('#video-container').empty();
            }
          }
  });
if(navigator.platform == 'iPad' || navigator.platform == 'iPhone' || navigator.platform == 'iPod')
{
  $(window).scroll(function() {
    var y = $(window).scrollTop();
    $("#supersized").css('top', y);
  });

//     $("#supersized").css("position", "static");
};
  
  var resizeTimer = null;
  $(window).bind('resize', function() {
    if (resizeTimer) clearTimeout(resizeTimer);
    resizeTimer = setTimeout(resizeCollection, 100);
  });  
});


