/* 
    Author: KIK-IT :: Kennis Is Kracht - Internet Toepassingen
    Website: http://www.kik-it.nl 
*/

    /* WIDGETS: GLOBAL */
    /* ----------------------------------------------------------------------------------- */
  
  /* SCRIPT TO SHOW THE TWITTERFEED IF VIEWPORT IS LARGE */
    var bodyWidth = parseInt($(window).width());
  if(bodyWidth > 1400)
  {
    $('#macroTwitterFeed').addClass('open');    
    $('#macroTwitterFeed').css('right','0px');
  }
  /* CLICK FUNCTION FOR THE LABEL */
  $('#macroTwitterFeedLabel').click(
    function(){        
      //Check currentState
      var setRightTo = '+=200';        
      if($('#macroTwitterFeed').hasClass('open'))
      {
        setRightTo = '-=200';
        $('#macroTwitterFeed').removeClass('open');  
      }
      else{
        $('#macroTwitterFeed').css('z-index', 999999);
        $('#macroTwitterFeed').addClass('open');
      }
      //Do animate
      $('#macroTwitterFeed').animate({          
        right: setRightTo          
        }, 1000, function() {
        // Animation complete.
        });
    }
  );  

  

    /* CONTENT: HOME */
    /* ----------------------------------------------------------------------------------- */


    function mycarousel_initCallback(carousel)
    {
        // Disable autoscrolling if the user clicks the prev or next button.
        carousel.buttonNext.bind('click', function() {
            carousel.startAuto(0);
        });
     
        carousel.buttonPrev.bind('click', function() {
            carousel.startAuto(0);
        });
     
        // Pause autoscrolling if the user moves with the cursor over the clip.
        carousel.clip.hover(function() {
            carousel.stopAuto();
        }, function() {
            carousel.startAuto();
        });
    };
 






    /* CONTENT: FOTOS */
   function albumSetPhotoDetail(url,position,width,height,albumId,pageNumber,numberOfRecords)
    {   
    
      /* SETUP PHOTO NAV */   
    var pageSize = 30;
    var pageRangeFrom = ((parseInt(pageNumber) - 1) * pageSize) + 1;
    var pageRangeTo   = parseInt(pageNumber) * pageSize; 
    if(pageRangeTo > numberOfRecords)
    {
      pageRangeTo = numberOfRecords;
    }
    
    var nextPos = parseInt(position) + 1;
    var prevPos = parseInt(position) - 1;
    var nextPhoto = "";
    var prevPhoto = "";
      
    /* CALCULATE WIDTH and HEIGHT */
    var newWidth = 530;
    var newHeight = 440;

    var ratio = width / height;
    if(ratio > 1) /* breder */
    {
      newHeight = Math.floor(newWidth / ratio);    
    }
    else
    {
      newWidth = Math.floor(newHeight * ratio);
    }
    
    // CREATE PHOTO HTML
    $('#photoContainer').html('<img class="dropshadowNormal" id="currentPhoto" align="right" width="' + newWidth + '" height="' + newHeight + '" src="' + url + ');" rel="' + position + '"/>');      

    // CREATE PREV BUTTON
    var prevButtonStyle = "style=\"width:265px; height:"+newHeight.toString()+"px; margin-top:-"+newHeight+"px; margin-left:10px; background-position:center left; background-repeat:no-repeat; background-image:url(/assets/discotheek/images/lightbox_prev.png); text-align:left; display:block; float:left;\"";
    if(prevPos > pageRangeFrom && prevPos <= pageRangeTo)
    {      
      //var prevButtonClick = $("#photo"+prevPos.toString()).attr("onclick");
      prevPhoto = "<a id=\"btnPrev\" href=\"#\" "+prevButtonStyle+">&nbsp;</a>";
      $('#photoContainer').append(prevPhoto);
      $('#btnPrev').click(function () {
        $('#photo'+prevPos).click();
      });
    }  
      
    // CREATE NEXT BUTTON
    var nextButtonStyle = "style=\"width:265px; height:"+newHeight.toString()+"px; margin-top:-"+newHeight+"px; margin-right:10px; background-position:center right; background-repeat:no-repeat; background-image:url(/assets/discotheek/images/lightbox_next.png);text-align:right; display:block; float:right;\"";
    if(nextPos >= pageRangeFrom && nextPos < pageRangeTo)
    { 
      nextPhoto = "<a id=\"btnNext\" href=\"#\" "+nextButtonStyle+">&nbsp;</a>";      
      $('#photoContainer').append(nextPhoto);
      $('#btnNext').click(function () {
        $('#photo'+nextPos).click();
      });
    }  
      
      
    // CREATE PHOTO COMMENTS  
    $('#photoContainer').append('<iframe style="padding:0px;" class="facebookScrolBar" width="560" MARGINHEIGHT="0" MARGINWIDTH="0" height="500" transparent="yes" hspace="0" vspace="0" border="none" src="http://theapollo.nl/_ajax/ajax_facebook_fotoalbum_fotocomments?albumId=' + albumId + '&page=' + pageNumber + '&photoUrl=' + url + '&currentUrl=/foto\'s/album"></iframe>');  
     
  }
  
  function albumNextPhotoDetail(position,maxPosition)
  {
      
  }
  
  function albumGetFirstPhotoDetail(url,position,width,height,albumId,pageNumber)
    {
    var newWidth = 540;
    var newHeight = 440;

    var ratio = width / height;
    if(ratio > 1) /* breder */
    {
      newHeight = Math.floor(newWidth / ratio);    
    }
    else
    {
      newWidth = Math.floor(newHeight * ratio);
    }
  
    return '<img id="currentPhoto" align="right" width="' + newWidth + '" height="' + newHeight + '" src="' + url + ');" rel="' + position + '"/>';
    
  }
  


  /* CONTENT: VIDEOS */
  /* ----------------------------------------------------------------------------------- */
  
  function openYoutubeDialog(videoId,videoWidth,videoHeight)
  {
    //Temp add dialog container to html
    $('<div id="dialog">&nbsp;</div>').appendTo('body');            
    //event.preventDefault();
    
    var dialogOpts = {
        modal: true,
        autoOpen: false,
    closeText: 'x sluiten',
    closeOnEscape: false,
        height: parseInt(videoHeight),
        width: parseInt(videoWidth),
        open: function() {
        //display correct dialog content
        $("#dialog").load('/_ajax/ajax_youtube_videoinchromelessplayer_byvideoid?videoId=' + videoId + '&videoWidth=' + videoWidth + '&videoHeight=' + videoHeight, function() {
          $('#dialog').fadeIn();
          });        
        },
      beforeclose: function () {        
      $('.slider').remove();
      },
      close: function () {
        $('#dialog').remove();
        }
    };
    
    $("#dialog").dialog(dialogOpts);    
    $("#dialog").dialog("open");
  
  //Bind to the ui-widget-overlay and watch for when it is clicked
    $('.ui-widget-overlay').click( function() {
         //Close the dialog
         $("#dialog").dialog("close");
    });   
  }




  /* CONTENT: EVENTS */
  /* ----------------------------------------------------------------------------------- */
  
  function openVoorverkoopDialog()
  {
    //Temp add dialog container to html
    $('<div id="dialog">&nbsp;</div>').appendTo('body');            
    //event.preventDefault();
    
    var dialogOpts = {
        modal: true,
        autoOpen: false,
    closeText: 'x sluiten',
    closeOnEscape: false,
        height: 525,
        width: 500,
        open: function() {
        //display correct dialog content
        $("#dialog").load('/_ajax/ajax_paylogic_voorverkoop', function() {
          $('#dialog').fadeIn();
          });        
        },
      beforeclose: function () {        
      $('.slider').remove();
      },
      close: function () {
        $('#dialog').remove();
        }
    };
    
    $("#dialog").dialog(dialogOpts);    
    $("#dialog").dialog("open");
  
  //Bind to the ui-widget-overlay and watch for when it is clicked
    $('.ui-widget-overlay').click( function() {
         //Close the dialog
         $("#dialog").dialog("close");
    });   
  }



  
  
  
  
   /* CONTROL: INSCHRIJVEN NIEUWSBRIEF */
  /* ----------------------------------------------------------------------------------- */
 
    $(document).ready(function () {
        $('.ctrlInschrijvenNieuwsbriefTxtNaam').bind('click', function () {
            $('.ctrlInschrijvenNieuwsbriefTxtNaam').val('');
        })
        $('.ctrlInschrijvenNieuwsbriefTxtEmail').bind('click', function () {
            $('.ctrlInschrijvenNieuwsbriefTxtEmail').val('');
        })
    });








