function initHTML5(){document.createElement("header");document.createElement("section");document.createElement("footer");document.createElement("article");document.createElement("nav");}function scriptLoader(src,f){var head= document.getElementsByTagName('head')[0];var script= document.createElement('script');script.type= 'text/javascript';script.src= src;head.appendChild(script);if(typeof(f) == 'function'){f();}}function styleLoader(src){
var head= document.getElementsByTagName('head')[0];var style= document.createElement('link');style.type= 'text/css';style.href= src;style.rel = "stylesheet";head.appendChild(style);}
initHTML5();
var page = {};page.redirect = function(href){var location = $('base').attr('href');window.location = location + href;};

/*Site Extensions
* Only contain functions available to the frontend
* Backend functions are stored elsewhere in the cms.functions file 
*/
var Extensions = {
    
    
        StyleLoader: function (src){
        
        var head= document.getElementsByTagName('head')[0];var style= document.createElement('link');style.type= 'text/css';style.href= src;style.rel = "stylesheet";head.appendChild(style);
    
        },    
    
        RenderGallery : function (gallery_id, showraw, lightbox, oneimagegallery){
           /*the code that a user plugs in 
           * showraw = true - the raw images will be rendered!
           * eg 
           * <div class='gallery-holder' id='gallery-holder-1'></div>
           * <script>Extensions.RenderGallery(1,false,false,false);<script> 
           * functionality:
           * onpageload - request page : common/site/plugins/g.php
           * the page g.php will call on CMSGallery::renderImageGallery() and echo the result
           * the result will be loaded in the defined div above
           * 
           * Note:
           * oneimagegallery means only 1 image is visible and onlick of that image, the gallery
           * is launched via lightbox!!!!
           */
                /*
               * Check to see if the stylesheet is loaded 
               */
               
               if($('link[href="../css/common/cmsfeatures.css"]').length == 0){
                   Extensions.StyleLoader ('../css/common/cmsfeatures.css');
               }
           $.post('../common/site/plugins/g.php',{act:3,gid:gallery_id,sr:showraw,lb:lightbox,og:oneimagegallery},function(r){
               
               $('#gallery-holder-'+gallery_id).html(r);
               

               
           });
        },
        
        ImageGallery : function (gid, val){
          /*renders either lightbox or window.open on image gallery!
          * This function is returned from g.php after RenderGallery is called
          * it thens calls either lightbox
          * $('#image-gallery-val ul li a').lightbox(options);
          * or 
          * A click handler which will append window.open to each anchor
          * and feed the href as the window's location!
          * $('#image-gallery-val ul li a').click(function(){});
          */
          
           if(val == 1){
               //lightbox
               $.get('../scripts/jquery-lightbox-0.5/js/jquery.lightbox-0.5.min.js',function(){
                   styleLoader('../scripts/jquery-lightbox-0.5/css/jquery.lightbox-0.5.css');
                   $('#image-gallery-'+gid+" ul li a").lightBox({
                       imageLoading: '../scripts/jquery-lightbox-0.5/images/lightbox-ico-loading.gif',
                       imageBtnClose: '../scripts/jquery-lightbox-0.5/images/lightbox-btn-close.gif',
                       imageBtnPrev: '../scripts/jquery-lightbox-0.5/images/lightbox-btn-prev.gif',
                       imageBtnNext: '../scripts/jquery-lightbox-0.5//images/lightbox-btn-next.gif'
                   });
               });
           }
           else{
               
           }
            
        }
        
      
};
