function flowplayer_set(){
   $f("player", "flash/flowplayer-3.1.5.swf", {            
            clip: {                   
                    autoPlay: true
            },				
            
            plugins:  { 
                    controls: {						
                            all:false, 
                            scrubber:true, 
                            play:true, 
                            mute:true
                    }	
            },
            play:{opacity:0}             
    }).playlist(".video-list li", {
            loop:false //if true, then each clip is advanced to the next clip when it ends				
    }); 
}

function carousel(){
   jQuery('#main-carousel').jcarousel({
        start: 1,
        scroll:1,
        animation:"fast",
        auto:3,
        wrap:"last"
    });
}

function gallery(){
   $('#gallery a').lightBox();
}

function loadPrimaryLOBCarousel() {
    $("#picture-list a").click(function() {
        var li = $(this).closest("li");
        var carousel = $(this).closest("ul");
        var index = $("li", carousel).index(li);
        $("#player-wrapper img").addClass("hidden").eq(index).removeClass("hidden");        
        return false;
    });
}

function setDatepicker(){
   $('#datepicker').datepicker({
            changeMonth: true,
            changeYear: true,
            minDate: 0
    });
}

function emailValidate(email){
   var emailRE = /^[a-zA-Z0-9_\+-]+(\.[a-zA-Z0-9_\+-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.([a-zA-Z]{2,4})$/;
   if (email.match(emailRE)){
      return true;
   }
   else {
      return false;
   }
}

function fromValidation(){
   var error = 0;
   
   var form = $('#formContact')[0];
   $(form.contact_name).removeClass('form-error')
   $(form.contact_email).removeClass('form-error')
   
   if (form.contact_name.value == ""){      
      $(form.contact_name).addClass('form-error')
      error = 1;
   }
   
   if (!emailValidate(form.contact_email.value)){      
      $(form.contact_email).addClass('form-error')
      error = 1;
   }
   
   if (error == 1){
      return false;
   }
   else{
      alert("Thanks for contact us!!\nWe'll get back to you as soon as possible.")
      return true;
   }
}

function pngFixer(){
   // Fix background images
   $("a").pngfix();
   $("div.btn1").pngfix();
   $("div.btn1 div").pngfix();
   $("div.btn2").pngfix();
   $("div.btn2 div").pngfix();
   $("div.btn3").pngfix();
   $("div.btn3 div").pngfix();
   $(".module-2").pngfix();
   $(".module-3").pngfix();
   
   $("#facebook-icon").pngfix({
      sizingMethod: "scale"
   });
   
   $("#twitter-icon").pngfix({
      sizingMethod: "scale"
   });
   
   $("#youtube-icon").pngfix({
      sizingMethod: "scale"
   });
   
   $(".module-1 img").pngfix({
      sizingMethod: "scale"
   });
   
   $(".module-2 img").pngfix({
      sizingMethod: "scale"
   });
   
   $(".module-3 img").pngfix({
      sizingMethod: "scale"
   });
}

/*************************Document Load******************************/
$(document).ready(function() {
   
   if($.browser.msie && $.browser.version=="6.0"){
      pngFixer();
   }
   
   $('#formContact').submit(function() {
      return fromValidation();
   });
   
   loadPrimaryLOBCarousel();
   gallery();
   carousel();
   flowplayer_set();
   $f().play()
});
