jQuery(document).ready(
    function ()
    {
        roundCorners ( '.jspTrack, .jspVerticalBar, .FG-2011-ROUND-CORNERS' );

        jQuery ( '.FG-2011-SCROLLABLE:visible' ).jScrollPane();
        
        preloadRollovers ( '.image-rollover' );
        
        activateRollovers ( '.image-rollover', '-over', '-base' );

        activateSwitchClicks ( '.image-switchclick', '-over', '-click' );
 
        activateHeaderBanners ( );
        
        jQuery ( 'DIV#FG-2011-POPUP-FORM-HEADER-CONTAINER > A' ).click ( 
            function ( )
            {
                // this is now called inline in the form template.
                //jQuery.unblockUI();
            }
        );
        
        jQuery ( 'a[href="{CONTACTUS}"]' ).attr ( 'href', 'javascript:;' ).click ( 
            function ( )
            {
                loadModal({'container_id':'FG-2011-MODAL-OUTER-CONTAINER','url':'/tools/contactenos', 'topDistance' : '200px'});
            }
        );

        jQuery ( 'a[href="{REGISTER_PROPERTY}"]' ).attr ( 'href', 'javascript:;' ).click ( 
            function ( )
            {
                loadModal({'container_id':'FG-2011-MODAL-OUTER-CONTAINER','url':'/utilities/tools/nosotros_podemos_ayudarlo', 'topDistance' : '200px'});
            }
        );
        
        activateSubmitWithJgrowl ( { 
            'submit_button' : jQuery ( '#FG-2011-FOOTER-NEWSLETTER-FIELD-CONTAINER a' ),
            'message_container' : '#FG-2011-REGISTRATION-STATUS',
            'response_container' : '#FG-2011-REGISTRATION-STATUS',
            'main_container' : '#FG-2011-BODY-CONTAINER',
            'method' : 'GET'
        } );
    }
);

function preloadRollovers ( strSelector )
{
    jQuery ( strSelector ).each (function (){
        var cacheImage = document.createElement('img');
        cacheImage.src = jQuery (this).attr( 'src' ).replace ( /-base/i, '-over' );
    });
}

function activateRollovers ( strSelector, overSuffix, baseSuffix )
{
    jQuery ( strSelector ).hover ( 
        function ( ) {
            var objRegExp = new RegExp ( baseSuffix, "gi" );

            jQuery (this).attr( 'src', jQuery (this).attr( 'src' ).replace ( objRegExp, overSuffix ) );
        }, function ( ) {
            var objRegExp = new RegExp ( overSuffix, "gi" );

            jQuery (this).attr( 'src', jQuery (this).attr( 'src' ).replace ( objRegExp, baseSuffix ) );
        }
    );
}

function activateSwitchClicks ( strSelector, baseSuffix, clickSuffix )
{
    jQuery ( strSelector ).click ( 
        function ( ) {
            var objRegExp = new RegExp ( baseSuffix, "gi" );

            jQuery (this).attr( 'src', jQuery (this).attr( 'src' ).replace ( objRegExp, clickSuffix ) );
        }
    );
}

function roundCorners ( strSelector )
{
    jQuery ( strSelector ).corner();
}

function activateHeaderBanners ( )
{
    // get the first element for the header banners
    var firstElement = getFirstBannerItem ( );
    
    // get the banner container element
    var bannerContainer = getBannerContainer ( );
    
    // get the image and copy
    var firstElementImageSrc = getImageFromBannerItem ( firstElement );
    var firstElementCopyHtml = getCopyFromBannerItem ( firstElement );
    
    // set the first element as the current banner
    setBannerBackground ( bannerContainer, firstElementImageSrc );
    
    // set the copy
    setBannerCopy ( bannerContainer, firstElementCopyHtml );
    
    // mark the element as active
    markActiveBannerItem ( firstElement );
    
    // bind the next and previous events to the arrows in the header
    jQuery ( '#FG-2011-HEADER-BANNER-RIGHT-ARROW-CONTAINER a' ).click (
        function ( )
        {
          event.preventDefault();

            // go to the next banner
            loadNextBanner ();
            return false;
        }
    );
    
    jQuery ( '#FG-2011-HEADER-BANNER-LEFT-ARROW-CONTAINER a' ).click (
        function ( )
        {
          event.preventDefault();
            // go to the previous banner
            loadPrevBanner ();
            return false;
        }
    );
    
    // bind the event to the counter nav items
    jQuery ( '.FG-2011-HEADER-BANNER-NAV-ITEM a' ).click (
        function ( event )
        {
          event.stopPropagation();
            loadBanner ( this );
        }
    );

    setInterval("loadNextBanner ()",10000);
}

function loadBanner ( clickedElement )
{
    if ( !clickedElement )
    {
        return false;
    }
    
    // get the parent of the clicked element
    var clickedContainer = jQuery ( clickedElement ).parent ();
    
    setBannerData ( getBannerContainer ( ), clickedContainer );
}

function getBannerContainer ( )
{
    return jQuery ( '#FG-2011-HEADER-BANNER-CONTAINER' );
}

function setBannerBackground ( bannerContainer, bannerImage )
{
    bannerContainer.css ( 'background-image', 'url(' + bannerImage + ')' );
}

function setBannerCopy ( bannerContainer, bannerCopy )
{
    bannerContainer.click(function () { 
      window.location=bannerCopy;
    });
}

function getCopyFromBannerItem ( bannerItem )
{
    if ( bannerItem.length == 0 )
    {
        return false;
    }
    
    // get the copy
    return bannerItem.find ( '.hidden' ).find ( '.copy' ).html();
}

function getImageFromBannerItem ( bannerItem )
{
    if ( bannerItem.length == 0 )
    {
        return false;
    }
    
    return bannerItem.find ( '.hidden' ).find ( '.image' ).find ( 'img' ).attr ( 'src' );
}

function getActiveBannerItem ( )
{
    // determine what the active banner is
    return jQuery ( 'DIV.FG-2011-HEADER-BANNER-NAV-ITEM.active' );
}

function removeActiveBannerMark ( )
{
    getActiveBannerItem ( ).removeClass( 'active' );
}

function loadNextBanner ( )
{
    // determine the current banner
    var activeBannerItem = getActiveBannerItem ();
    
    // determine what the next banner is
    var nextBannerItem = activeBannerItem.next ();
    
    // check if we got a valid result
    if ( nextBannerItem.length == 0 )
    {
        nextBannerItem = getFirstBannerItem ();
    }
    
    setBannerData ( getBannerContainer ( ), nextBannerItem );
}

function loadPrevBanner ( )
{
    // determine the current banner
    var activeBannerItem = getActiveBannerItem ();
    
    // determine what the previous banner is
    var prevBannerItem = activeBannerItem.prev ();
    
    // check if we got a valid result
    if ( prevBannerItem.length == 0 )
    {
        prevBannerItem = getLastBannerItem ();
    }
    
    setBannerData ( getBannerContainer ( ), prevBannerItem );
}

function setBannerData ( bannerContainer, bannerItem )
{
    // check data
    if ( bannerContainer.length == 0 || bannerItem.length == 0 )
    {
        return false;
    }
    
    // get the image and copy
    var bannerImageSrc = getImageFromBannerItem ( bannerItem );
    var bannerCopyHtml = getCopyFromBannerItem ( bannerItem );
    
    // set the first element as the current banner
    setBannerBackground ( bannerContainer, bannerImageSrc );
    
    // set the copy
    setBannerCopy ( bannerContainer, bannerCopyHtml );
    
    // remove the current active mark
    removeActiveBannerMark ();
    
    // mark the element as active
    markActiveBannerItem ( bannerItem );
}

function markActiveBannerItem ( bannerItem )
{
    if ( bannerItem.length > 0 )
    {
        bannerItem.addClass ( 'active' );
    }
}

function getFirstBannerItem ( )
{
    return jQuery ( '.FG-2011-HEADER-BANNER-NAV-ITEM' ).first ();
}

function getLastBannerItem ( )
{
    return jQuery ( '.FG-2011-HEADER-BANNER-NAV-ITEM' ).last ();
}

function loadModal ( modalOptions )
{
    
    if ( '' == modalOptions.topDistance )
    {
  modalOptions.topDistance = '70%';
    }

    load ({
        'container_id' : modalOptions.container_id,
        'url' : modalOptions.url,
        'post_data' : modalOptions.post_data,
        'callback' : function ( ) {
            jQuery.unblockUI();
            jQuery.blockUI({
                centerX: true,
                centerY: (jQuery.browser.msie && parseInt(jQuery.browser.version) === 6) ? false : true ? false : true, 
                allowBodyStretch: false,
                showOverlay: true,
                applyPlatformOpacityRules: false, 
                message: jQuery ('#' + modalOptions.container_id ),
                css : { 
                    border : 'none', 
                    backgroundColor : 'none', 
                    cursor : 'default',
                    width:          '100%',
                    height:         '100%',  
                    top:            modalOptions.topDistance, 
                    left:           '0',
                    textAlign:      'center'
                },
                overlayCSS : { backgroundColor : '#474747', opacity : 0.4 }
            });
            jQuery('.blockOverlay').attr('title','Click to close').click(jQuery.unblockUI);
            jQuery('.blockUI.blockPage').css('position','absolute');
        }
    });
}

function load ( loadOptions )
{
    jQuery.blockUI({ 
        centerX: true,
        centerY: true, 
        showOverlay: true,
        applyPlatformOpacityRules: false,
        message:  "Cargando...",
        css : { 
            border : 'none', 
            backgroundColor : 'none'
        },
        overlayCSS : { backgroundColor : '#93dee1', opacity : 0.4 }
    });

    jQuery ( '#' + loadOptions.container_id ).load (
        loadOptions.url,
        loadOptions.post_data,
        function ( )
        {
            if ( jQuery.isFunction ( loadOptions.callback ) )
            {
              loadOptions.callback ( );
            }
        }
    );
    
    return false;
}


function activateSubmitForm ( objParams )
{
    if ( objParams.submit_button.length <= 0 )
    {
        return false;
    }
    
    objParams.submit_button.click ( 
        function ( )
        {
            var objForm = jQuery ( this ).parents ( 'form' ).first ( );

            if ( objForm.length <= 0 )
            {
                return false;
            }

    if ( true == objParams.validate )
    {
        if ( false == objParams.validate_function() )
        {
      return false;
        } 
    }

            jQuery ( objParams.main_container ).block({ 
                centerX: true,
                centerY: true, 
                showOverlay: true,
                applyPlatformOpacityRules: false,
                message:  "Procesando...",
                css : { 
                    border : 'none', 
                    backgroundColor : 'none'
                },
                overlayCSS : { backgroundColor : '#474747', opacity : 0.4 }
            });
            
            if ( !objParams.url )
            {
                objParams.url = objForm.attr ( 'action' );
            }

            jQuery ( objParams.message_container ).load ( 
                objParams.url + ' ' + objParams.response_container, 
                objForm.serializeArray (), 
                function (responseText){
                    jQuery ( objParams.main_container ).unblock();
                    jQuery ( objParams.message_container ).html(jQuery ( objParams.response_container ).children().html());
                    jQuery ( objParams.message_container ).fadeIn('slow');
                }
            );
        }
    );
}

function activateSubmitWithJgrowl ( objParams )
{
    if ( objParams.submit_button.length <= 0 )
    {
        return false;
    }
    
    objParams.submit_button.click ( 
        function ( )
        {
            var objForm = jQuery ( this ).parents ( 'form' ).first ( );

            if ( objForm.length <= 0 )
            {
                return false;
            }

            jQuery ( objParams.main_container ).block({ 
                centerX: true,
                centerY: true, 
                showOverlay: true,
                applyPlatformOpacityRules: false,
                message:  "Procesando...",
                css : { 
                    border : 'none', 
                    backgroundColor : 'none'
                },
                overlayCSS : { backgroundColor : '#474747', opacity : 0.4 }
            });
            
            if ( !objParams.url )
            {
                objParams.url = objForm.attr ( 'action' );
            }
            
            if ( objParams.method == 'GET' )
            {
                var submitData = objForm.serialize ();
            }
            else
            {
                var submitData = objForm.serializeArray ();
            }

            jQuery ( objParams.message_container ).load ( 
                objParams.url + ' ' + objParams.response_container, 
                submitData, 
                function (responseText){
                    jQuery ( objParams.main_container ).unblock();
                    jQuery.jGrowl(jQuery ( objParams.response_container ).children().html());
                }
            );
        }
    );
}


function ajaxifyUrl ( url )
{
  // init var
  var strTemplate = "";
  
  // if we"ve given a second parameter then it should overwrite whatever template we have
  if ( arguments[1] != "" )
  {
     strTemplate = "&tpid=" + arguments[1];
  }
  
  var returnUrl = "http://" + location.host + "/relay.php?ejaxKey=PublicAjaxPageRunner.run&url=" + url + "&format=html" + strTemplate;
  
  return returnUrl.replace ( /(#[a-z0-9]+)/ig, "" );
}

function clearText(field){
      if (field.defaultValue == field.value) field.value = '';
      else if (field.value == '') field.value = field.defaultValue;
     }

var intervalId = 0;

function activateGallery2 ( objOptions )
{ 
    // get the first element for the header banners
    var firstElement = getFirstBannerItem2 ( objOptions.bannerItemContainerSelector );
    
    // get the banner container element
    var bannerContainer = getBannerContainer2 ( objOptions.bannerWrapperSelector );
  
    // get the banner image container
    var bannerImageContainer = getBannerContainer2 ( objOptions.bannerImageContainerSelector );
  
    // check if we're showing image popup. We need to set it up before loading the first image.
    if ( true === objOptions.popUpImageOnClick )
    {
      bannerContainer.append ( "<a id='" + objOptions.largeImageContainer + "' title='" + objOptions.popupClickMessage + "'></a>" );
      jQuery ( "a" + objOptions.largeImageContainerSelector ).fancybox ({autoScale: false});
    }

    // set the first element as the current banner
    setBannerData2 ( firstElement, objOptions );

    // bind the next and previous events to the arrows in the header
    jQuery ( objOptions.nextArrowSelector ).click (
        function ( )
        {
            // go to the next banner
            loadNextBanner2 ( objOptions );
            return false;
        }
    );

    jQuery ( objOptions.prevArrowSelector ).click (
        function ( )
        {
            // go to the previous banner
            loadPrevBanner2 ( objOptions );
            return false;
        }
    );
    
    // bind the event to the counter nav items
    jQuery ( objOptions.itemCounterSelector ).click (
        function (  )
        {
            loadBanner2 ( this, objOptions );
        }
    );

    if ( objOptions.autoplayInterval > 0 )
    {
      intervalId = setInterval ( function ( ){loadNextBanner2 ( objOptions )}, objOptions.autoplayInterval );
    }
}

function loadBanner2 ( clickedElement, objOptions )
{
    if ( !clickedElement )
    {
        return false;
    }

    // get the data from the clicked element
    setBannerData2 ( clickedElement, objOptions );
}

function getBannerContainer2 ( bannerContainerSelector )
{
    return jQuery ( bannerContainerSelector );
}

function setBannerBackground2 ( bannerContainer, bannerImage )
{
    bannerContainer.css ( "background-image", "url(" + bannerImage + ")" );
}

function setBannerAttribute2 ( bannerContainer, bannerAttribute, bannerAttributeContainerSelector )
{
    bannerContainer.find ( bannerAttributeContainerSelector ).html( bannerAttribute );
}

function setBannerElementAttribute2 ( bannerContainer, bannerAttribute, elementAttribute, bannerAttributeContainerSelector )
{
    bannerContainer.find ( bannerAttributeContainerSelector ).attr( elementAttribute, bannerAttribute );
}

function getBannerAttribute2 ( bannerItem, selector )
{
    if ( bannerItem.length == 0 )
    {
        return false;
    }
    
    // get the copy
    return jQuery ( bannerItem ).find ( ".hidden" ).find ( selector ).html();
}

function getImageFromBannerItem2 ( bannerItem )
{
    if ( bannerItem.length == 0 )
    {
        return false;
    }
    
    return jQuery ( bannerItem ).find ( ".hidden" ).find ( ".image" ).find ( "img" ).attr ( "src" );
}

function getActiveBannerItem2 ( bannerItemContainerSelector )
{
    // determine what the active banner is
    return jQuery ( bannerItemContainerSelector + ".active" );
}

function removeActiveBannerMark2 ( bannerItemContainerSelector )
{
    getActiveBannerItem2 ( bannerItemContainerSelector ).removeClass( "active" );
}

function loadNextBanner2 ( objOptions )
{
    // determine the current banner
    var activeBannerItem = getActiveBannerItem2 ( objOptions.bannerItemContainerSelector );

    // determine what the next banner is
    var nextBannerItem = jQuery ( activeBannerItem ).next ( objOptions.bannerItemContainerSelector );
  
    // check if we got a valid result
    if ( nextBannerItem.length == 0 )
    {
        nextBannerItem = getFirstBannerItem2 ( objOptions.bannerItemContainerSelector );
    }
    
    setBannerData2 ( nextBannerItem, objOptions );
}

function loadPrevBanner2 ( objOptions )
{
    // determine the current banner
    var activeBannerItem = getActiveBannerItem2 ( objOptions.bannerItemContainerSelector );
    
    // determine what the previous banner is
    var prevBannerItem = activeBannerItem.prev ( objOptions.bannerItemContainerSelector );
    
    // check if we got a valid result
    if ( prevBannerItem.length == 0 )
    {
        prevBannerItem = getLastBannerItem2 ( objOptions.bannerItemContainerSelector );
    }
    
    setBannerData2 ( prevBannerItem, objOptions );
}

function setBannerData2 ( bannerItem, objOptions )
{
    // get banner container
    var bannerContainer = getBannerContainer2 ( objOptions.bannerWrapperSelector );
  
    // get banner image container
    var bannerImageContainer = getBannerContainer2 ( objOptions.bannerImageContainerSelector );
  
    // check data
    if ( bannerContainer.length == 0 || bannerImageContainer.length == 0 || bannerItem.length == 0 )
    {
        return false;
    }
  
    // get the image and copy
    var bannerImageSrc = getImageFromBannerItem2 ( bannerItem );
    var bannerCopyHtml = getBannerAttribute2 ( bannerItem, ".body" );
    var bannerTitleHtml = getBannerAttribute2 ( bannerItem, ".title" );
    var bannerLinkHtml = getBannerAttribute2 ( bannerItem, ".link" );
  
    if ( objOptions.fadeOutContainerSelector != "" )
    {
      jQuery ( objOptions.fadeOutContainerSelector ).fadeOut ( function ( ){
        // set the first element as the current banner
        setBannerBackground2 ( bannerImageContainer, bannerImageSrc );
        
        // set the copy
        setBannerAttribute2 ( bannerContainer, bannerCopyHtml, objOptions.bannerCopyContainerSelector );
    
        // set the title
        setBannerAttribute2 ( bannerContainer, bannerTitleHtml, objOptions.bannerTitleContainerSelector );
        
        // set the link
        setBannerAttribute2 ( bannerContainer, bannerLinkHtml, objOptions.bannerLinkContainerSelector );
        
        jQuery ( objOptions.fadeOutContainerSelector ).fadeIn ( );
      });
    }
    else
    {
        // set the first element as the current banner
        setBannerBackground2 ( bannerImageContainer, bannerImageSrc );
        
        // set the copy
        setBannerAttribute2 ( bannerContainer, bannerCopyHtml, objOptions.bannerCopyContainerSelector );
    
        // set the title
        setBannerAttribute2 ( bannerContainer, bannerTitleHtml, objOptions.bannerTitleContainerSelector );
        
        // set the link
        setBannerAttribute2 ( bannerContainer, bannerLinkHtml, objOptions.bannerLinkContainerSelector );
    }
  
    // if an interval has been set, reset it.
    if ( objOptions.autoplayInterval > 0 )
    {
      clearInterval ( intervalId );
      intervalId = setInterval ( function ( ){loadNextBanner2 ( objOptions )}, objOptions.autoplayInterval );
    }
  
    // check if we've been asked to hide the copy container if the copy is null
    if ( objOptions.hideCopyContainerIfEmpty && !bannerCopyHtml )
    {
      jQuery ( objOptions.bannerCopyContainerSelector ).parent().hide ();
    }
    else if ( objOptions.hideCopyContainerIfEmpty && bannerCopyHtml != "" )
    {
      jQuery ( objOptions.bannerCopyContainerSelector ).parent().show ();
    }
  
    if ( true === objOptions.popUpImageOnClick )
    {
      // get the popup link
      var bannerPopupLinkHtml = getBannerAttribute2 ( bannerItem, ".popuplink" );
      
      // set the popup link
      setBannerElementAttribute2 ( bannerContainer, bannerPopupLinkHtml, "href", objOptions.largeImageContainerSelector );
    }

    // remove the current active mark
    removeActiveBannerMark2 ( objOptions.bannerItemContainerSelector );
    
    // mark the element as active
    markActiveBannerItem2 ( bannerItem );
}

function markActiveBannerItem2 ( bannerItem )
{
    if ( jQuery ( bannerItem ).length > 0 )
    {
        jQuery ( bannerItem ).addClass ( "active" );
    }
}

function getFirstBannerItem2 ( bannerItemContainerSelector )
{
    return jQuery ( bannerItemContainerSelector ).first ();
}

function getLastBannerItem2 ( bannerItemContainerSelector )
{
    return jQuery ( bannerItemContainerSelector ).last ();
}

/* Photo Gallery
------------------------------------------------------- */

function carousel(totalperpage,spacing,containerwidth) {
  
  $('.the-carousel-gallery').each(function()
  {
    //Carousel
    var total = $(this).find('.item').length;
    var items = $(this).find('.item');
    var itemsperpage = totalperpage;
    var total2 = Math.ceil(total / itemsperpage);
    var slideshow_width =  containerwidth || $(this).find('.navigation').width();
    var total_width = total2 * slideshow_width;
    var first = $(this).find('.item:first');
    var npos = 0;
    var padding = spacing || 0;
    var n = 0;
    var p = 0;

    //Create carousel thumbnails
    if($(this).find(".small").length) {
       $(this).find(".thumb,.thumb-link").each(function(i){   
           $(this).css("cssText","background:url("+$(this).find('.small').attr('src').replace(/ /g,"%20").replace(/'/g,"%27").replace("(","%28").replace(")","%29")+") no-repeat 50% 50%");
       });  
    }
    
    $(this).find(".screen").css("width","20000em");   
    
    //Add a wrapper every X items
    if($(this).parent(".ma-gallery").length) {
       for(var i = 0; i < total; i+=itemsperpage) {
          items.slice(i, i+itemsperpage).wrapAll("<div class='wrapper'></div>");
       } 
    }
    
    //Navigation for thumbnails
    $(this).find('.prev').unbind('click').bind('click',function(e) {
      e.preventDefault();
      npos--;
      if(npos < 0) npos = 0;
      (!Modernizr.csstransitions)?$(this).parents('.the-carousel-gallery').find('.screen').stop().animate({left:npos * -(slideshow_width+padding)}, 350):$(this).parents('.the-carousel-gallery').find('.screen').css({"left":npos * -(slideshow_width+padding)});
    });
    
    $(this).find('.next').unbind('click').bind('click',function(e) {
      e.preventDefault();
      npos++;
      if(npos >= total2) npos = total2-1;
      (!Modernizr.csstransitions)?$(this).parents('.the-carousel-gallery').find('.screen').stop().animate({left:npos * -(slideshow_width+padding)}, 350):$(this).parents('.the-carousel-gallery').find('.screen').css({"left":npos * -(slideshow_width+padding)});
    });
    
    //Navigation for image pane
    $(this).find('.next-pane').unbind('click').bind('click',function() {
         p = 0;
         $(this).parent().find(".thumb.active").parent().next().find(".thumb").click();
         if(n==1) {      
           $(this).parent().find(".next").click();
           $(this).parent().find(".thumb.active").parents(".wrapper").next().find(".thumb:first").click();
           n=0;
         }
         $(this).parent().find(".wrapper").each(function() {
           ($(this).find(".thumb:last").hasClass("active"))?n=1:false;
         });
    });
    $(this).find('.prev-pane').unbind('click').bind('click',function() {
         n = 0;
         $(this).parent().find(".thumb.active").parent().prev().find(".thumb").click();
         if(p==1) {      
           $(this).parent().find(".prev").click();
           $(this).parent().find(".thumb.active").parents(".wrapper").prev().find(".thumb:last").click();
           p=0;
         }
         $(this).parent().find(".wrapper").each(function() {
           ($(this).find(".thumb:first").hasClass("active"))?p=1:false;
         });

    });
   
    //Update gallery pane on click
    $(this).find(".thumb").unbind('click').bind('click',function(e) {
       e.preventDefault();

       $(this).parents(".navigation").prev().find("img").fadeOut().load(function() {
            $(this).fadeIn();
       }).attr("src",$(this).find("img").attr("url"));
       
       //text
       $(this).parents(".the-carousel-gallery").find(".info-pane h2").html($(this).find("img").attr("alt"));
       $(this).parents(".the-carousel-gallery").find(".info-pane span").html($(this).find("img").attr("desc"));

       $(this).parents(".the-carousel-gallery").find(".thumb").removeClass("active");
       $(this).addClass("active");
      
    });  
    
    //Init
    //$(this).parent().find(".info-pane h2").html($(this).find(".item img:first").attr("alt"));
    //$(this).parent().find(".info-pane span").html($(this).find(".item img:first").attr("desc"));
    //$(this).find(".thumb:first").addClass("active");
    $(this).find(".thumb:first").click();
    
  //end each()  
});  

}

var openPopup = window.open;

function show_msg(msg) { alert(msg); }

function validateForm() {
	missing_required = 0;

	for (i = 0; i < arguments.length; i++) {
		if(arguments[i] == '') {
			missing_required = 1;
		}
	}

	if(missing_required) {
		alert("A required form field is missing.");
		return false;
	} else {
		return true;
	}
}

function expCustomLink(myURL) {
	location.href = myURL;
}

function setUrl(path) {
	document.location.href = path;
}

function expArticleLink(sectionId, articleId) {
	location.href = '/index.php?section_id=' + sectionId + '&section_copy_id=' + articleId;
}

function expPopupWindow(url, widthVal, heightVal, resizableVal, scrollbarsVal, toolbarVal, locationVal, directoriesVal, statusVal, menubarVal, copyHistoryVal) {

	var attributes = "width="  	 	 + widthVal       +
				 	 ",height=" 	 + heightVal      +
				 	 ",resizable="  + resizableVal  +
				 	 ",scrollbars="  + scrollbarsVal  +
				 	 ",toolbar=" 	 + toolbarVal 	  +
				 	 ",location=" 	 + locationVal 	  +
				 	 ",directories=" + directoriesVal +
				 	 ",status=" 	 + statusVal 	  +
				 	 ",menubar=" 	 + menubarVal 	  +
				 	 ",copyhistory=" + copyHistoryVal;

	window.open(url, 'WindowName', attributes);
}

function xprLog(msg) {
    if (window.console) console.log(msg);
}

if (document.addEventListener) {  
    document.addEventListener("DOMContentLoaded", function () { if (typeof onXprPageLoad == 'function') onXprPageLoad(); }, false);
} else if (document.attachEvent) {  
    document.attachEvent('DOMContentLoaded', function () { if (typeof onXprPageLoad == 'function') onXprPageLoad(); });
}  

