/*

        Authors: Ferenc Radius, Nuey San Waldman

*/

if (jQuery.browser.msie) { //IE returns null, so we work around that ...
    function $(var1, var2) {
        var element = jQuery(var1, var2);
        if (!element) {
            return new jQuery({});
        }
        
        return element;
    }
}

$(document).ready(function () {

// ________________________________________________________________________________________________
//                                                                                    G E N E R I C  
    if (jQuery.browser.msie) {
                // Global search tweaks
        $('q').prepend('&ldquo;').append('&rdquo;');
        $('#search #infobank_search_results').css('font-style', 'normal');
    }
    
    $('a[@href^="http://"]').attr('target', '_blank'); // Always open external sites in a new window 

    $('a[href$=.pdf]').attr('target', '_blank'); // Always open pdf files in a new window

    $('li#bookmark_link a').bookmarks(); // initialize bookmarks plugin

    $('#product_new div.component_feature div img').attr('style', 'display:block;');

    $('body.v_product p.contact_dealers, body.v_news p.contact_dealers, body.v_profile p.contact_dealers, body.v_technical p.contact_dealers').appendTo('div.page:last');

    $('#content > #infobank_container').prependTo('#content');

// ________________________________________________________________________________________________
//                                                                                            F A Q

    $('#faq_container li div').hide().addClass('hidden');
    $('#faq_container h2').click(function () {
    
        $('li>div').slideUp(150).removeClass('visible').addClass('hidden');
        
        var dejaVu = $(this).next('div');
        
        if (dejaVu.is(':hidden')) {
            $(this).next('div.hidden').slideDown(150).removeClass('hidden').addClass('visible');
        }
        return false;
    });

// ________________________________________________________________________________________________
//                                                                                  C A R O U S E L

    $('#mycarousel').jcarousel();

    $('#ec_carousel').jcarousel();
    
		$('#masterclass_shorts_carousel').jcarousel();

// ________________________________________________________________________________________________
//                                                                                    A C T I O N S

    /* Obsolete after the new audit, superseded by Options */
/*
    $("#actions dd").hide();
    $('dt#feedback').next('dd').show();
    $("#actions dt#feedback a, #actions dt#download a").click(function () {
        $("#actions dd:visible").slideUp(100);
        $(this).parent().next().slideDown(100);
        return false;
    });
*/

// ________________________________________________________________________________________________
//                                                                                    O P T I O N S

    $('#side #actions li ul').not(':first').hide().addClass('collapsed');
    // expands only the first nested list
        
    $('#actions li > span').hover(function () {
        $(this).css({
            "cursor": "pointer",
            "color": "#ED252A",
            "text-decoration": "underline"
        });
    }, function () {

    });
    
    $('#actions li > span').click(function () {
        var kungFu = $(this).next('ul');
        if (kungFu.is(':hidden')) {
            $('#actions li>ul').slideUp(250);
            $(this).next('ul').slideDown(250);
        } else {
            return false;
        }
    });
    
    if (jQuery.browser.msie && jQuery.browser.version.substring(0, 1) == '6') { //IE 6
        $('#actions li#downloads > span, #actions li#feedback > span').css({
            "padding-left": "28px",
            "display": "block"
        });
    }

// ________________________________________________________________________________________________
//                                                           S I D E  O V E R L A P P I N G  IE FIX
    if ( jQuery.browser.msie ) {

        if ( jQuery.browser.version.substring(0, 1) == '6' ) {
             $('body:has(div#side)').find('#content').css('height', $('#side').height() +'px');
        }

        else {
             $('body:has(div#side)').find('#content').css('min-height', $('#side').height() +'px');
        }
    }

});

// ________________________________________________________________________________________________
// 
/*##############################################################################
#
# CPN_showcase Javascript overlay
# Author:   Michel Ypma
# Date:     12-10-2007
#
#       NOTE: The showcase.swf is placed in the xhtml swf folder.
#
#
# Documentation:
#   This works on a elements. It only requires 2 properties.
#   1.  add a classname "CPN_showcase" to it. Now it will be found by this code.
#   2.  add a href attribute to it. This needs to tell where it can find the
#       XML definition and what the first image is
#
#   this the CSS used by the overlay and flashwrapper:*/
/*

#CPN_window {
  position:fixed;
  *position: absolute;
  width:100%;
  height:100%;
  z-index:100;
  left:0;
  top:0;
}

*/
/*
# Example:
#  <a class="CPN_showcase" href="./xml/showcase.xml?firstIamgeName">klik </span>
#
##############################################################################*/



/**
 * Function CPNShowcaseShow
 * opens the overlay and loads the flash in the browser.
 *
 * @param _xml location of the xml file
 */
function CPNShowcaseShow( _xml )
{

    var base = $('base').attr ( 'href' );

    CPNOverlay();

    $( '#CPN_window' ).css ( 'display', 'block' );

    var targ = "./files/swf/showcase.swf";
    if ( window.location.href.indexOf('ambassador') > -1 || 
		 window.location.href.indexOf('editors_choice') > -1 || 
		 window.location.href.indexOf('wpph_of_the_year_2008') > -1 || 
		 window.location.href.indexOf('visa_views_from_the_festival') > -1 || 
		 window.location.href.indexOf('visa_reports') > -1) {
        var date = new Date();
        targ = "./files/swf/ambassadors.swf?"+ date.getTime();
    }

    var so = new SWFObject  (targ, "CPN_window", "990", "760", "8", "");
    so.addVariable          ("xmlFile", _xml );
    so.addVariable          ("baseHref", base );
    so.addParam             ('wmode',   'transparent');
    so.write                ("CPN_window");

    $(window).bind          ( 'resize', CPNOverlay );
    $(window).bind          ( 'scroll', CPNOverlay );

    document.onkeyup = function(e){

        if ( e == null ) {    // ie
            keycode =   event.keyCode;
        } else {    // mozilla
            keycode =   e.which;

        }
        if(keycode == 27){  // close
            CPNShowcaseClose();
        }
    }
}

/**
 * Function CPNShowcaseClose
 * closes the overlay and unloads the flash in the browser.
 *
 */
function CPNShowcaseClose() {
    $( '#CPN_window' ).remove ( 'embed'               );
    $( '#CPN_window' ).empty  (                       );
    $( '#CPN_window' ).css    ( 'display', 'none'     );
    $( window ).unbind        ( 'resize', CPNOverlay  );
}

/**
 * Function CPNShowcaseShow
 * setup the overlay
 *
 */
function CPNOverlay() {
    if ( jQuery.browser.msie == true ) {
        $( '#CPN_window' ).css( 'top', document.documentElement.scrollTop );
    }
    $( '#CPN_window' ).css ( 'height', '100%'   );
    $( '#CPN_window' ).css ( 'width', '100%'    );
    }

/**
 * Event DocumentReady
 * initialize all CPN_showcase elements
 *
 */

$(document).ready(function(){
    $( 'a.CPN_showcase' ).click( function() {
        CPNShowcaseShow( $(this).attr( 'href' ) );
        return false;
    });

    $( '#footer' ).after( '<div id="CPN_window"><h1>Flash player not detected</h1><p>You must have a copy of the <a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash">Flash player</a> installed on your system for this component to function.</p><p>If you already have the Flash player installed, please make sure that JavaScript is enabled. For enabling JavaScript, please see your Web browser&#39;s Help.</p></div>' );
    if ( jQuery.browser.msie == true)
    $( '#CPN_window' ).css( 'postion', 'absolute' );
    $( '#CPN_window' ).css ( 'display', 'none' );
});




