(function($){  
 $.fn.slideshow = function(options) {  
  
  var defaults = {  
   width: 940,  
   height: 550,
   timeout: 5000
  };  
  var options = $.extend(defaults, options);  
      
  return this.each(function() {  
    obj = $(this);
    obj.wrap("<div class='slideshow'></div>");
    obj.addClass("slideshow_slides")
    obj.parent().append("<div class='slideshow_overlay'><p></p><div class='slideshow_nav'><a href='#' class='prev'>prev</a><a href='#' class='pause play_pause'>Play/Pause</a><a href='#' class='next'>next</a></div><div class='slideshow_pager'></div></div>");
    
    $('img', obj).wrap("<div class='slide'></div>");

    obj.cycle({
      fx: 'fade',
      pager: '.slideshow_pager',
      pause: false,
      timeout: options.timeout,
      prev: '.slideshow .prev',
      next: '.slideshow .next',
      before: function () {
        $('.slideshow_overlay p').html('Loading...');
        },
      after: function () {
        $('.slideshow_overlay p').html($('img', this).attr('alt'));
        }
	  });
	  
    $(".slideshow .play_pause").toggle(
      function () {
        $(this).addClass('play');
        $(this).removeClass('pause');
        obj.cycle('pause');
      },
      function () {
        $(this).addClass('pause');
        $(this).removeClass('play');
        obj.cycle('resume');
      }
    );

    /* Opacity change on hover -- Caused display errors in IE6  
    obj.parent().hover(
      function () {
        obj.parent().children('.slideshow_overlay').fadeTo(200,1.0);
      }, 
      function () {
      	obj.parent().children('.slideshow_overlay').fadeTo(200,.5);
      }
    );
    */
    

  });  
 };  
})(jQuery); 


(function($){  
 $.fn.mapeditor = function(options) {  
  
  var defaults = {};  
  var options = $.extend(defaults, options);  
      
  return this.each(function() {
    currentMarker = '';  
    obj = $(this);
    
    // Create Main Menu
    obj.append('<div id="editor_menu">'+
    '<button class="add">Add Marker</button>'+
    '<button class="generate">Generate Code</button>'+
    '</div>');

    // Create Code Dialog
    obj.append('<div id="code_dialog" style="cursor:move;"><p>'+
    '<label>Copy This Code:</label><textarea rows="10" id="marker_code"/>' +
    '<button class="cancel">Close</button>' +
    '</p></div>');
    codeDialog = $('#code_dialog', obj);
    codeDialog.draggable({containment: obj});
    // Cancel Button
    codeDialog.find('button.cancel').click(function(){
      codeDialog.hide();
      });
    codeDialog.hide();

    
    // Create Marker Dialog
    obj.append('<div id="marker_dialog" style="cursor:move;"><p>'+
    '<label>Title:</label><input type="text" id="marker_title"/>' +
    '<label>Subtitle:</label><input type="text" id="marker_subtitle"/>' +
    '<label>Legend Class:</label><select id="marker_class"></select>' +
    '<label>Link URL:</label><input type="text" id="marker_link"/>' +
    '<label><input type="checkbox" id="marker_open"/>Always open?</label>' +
    '<button class="save">Save</button>' +
    '<button class="cancel">Cancel</button>' +
    '</p></div>');
    markerDialog = $('#marker_dialog', obj);
    markerDialog.draggable({containment: obj});
    // Cancel Button
    markerDialog.find('button.cancel').click(function(){
      markerDialog.hide();
      });
      
    // Save Button
    markerDialog.find('button.save').click(function(){
      $('#markers #'+currentMarker,obj).find('a span strong').text(markerDialog.find('#marker_title').val());
      $('#markers #'+currentMarker,obj).find('a span em').text(markerDialog.find('#marker_subtitle').val());
      $('#markers #'+currentMarker,obj).attr('class',markerDialog.find('#marker_class').val());
      $('#markers #'+currentMarker,obj).find('a').attr('href',markerDialog.find('#marker_link').val());
      alwaysOpen = markerDialog.find('#marker_open').attr('checked');
      $('#markers #'+currentMarker,obj).find('a').toggleClass('open',markerDialog.find('#marker_open').attr('checked'));
      markerDialog.hide();;
      });    // Hide Marker Dialog Initially
    markerDialog.hide();
    
    // Initialize Markers
    initMarkers();

    // Create new marker when 'Add Marker' is clicked
    obj.find('#editor_menu button.add').click(function (){
        obj.find('#markers').append('<li><a style="left:0; top:50px;" class="open" href=""><span><strong>New</strong> <em>Marker</em></span></a></li>');
        initMarkers();
      });

    // Generate marker code when 'Generate Code' is clicked
    obj.find('#editor_menu button.generate').click(function (){
        code = '<ul id="markers">';
        $('#markers li', obj).each(function (i,val) {
          code = code + '<li class="' + $(this).attr('class') + '">' +
          '<a href="'+ $(this).find('a').attr('href') +'" class="' + $(this).find('a').attr('class') + '" style="left:' + $(this).find('a').css('left') + '; top:' + $(this).find('a').css('top') + ';" >'+
          '<span><strong>' +  $(this).find('a strong').text() + '</strong> <em>' + $(this).find('a em').text() + '</em></span>' +
          '</a></li>';
        });
        code = code + '</ul>'
        codeDialog.find('#marker_code').text(code);
        codeDialog.show();
        codeDialog.find('#marker_code').focus().select();
      });


    
    function initMarkers () {
      // Assign each marker with an ID
      $('#markers li', obj).each(function (i,val) {
          $(this).attr('id','marker_'+i)
        });
      // Make each marker draggable
      markers = $('#markers li a', obj).draggable({containment: obj, addClasses: false}).css('cursor','move').click(function() { return false; });
      // Add edit menu to each marker
      markers.find('span').append('<div class="marker_menu"><button class="delete">Delete</button><button class="edit">Edit</button></div>');
      // Delete button
      markers.find('.delete').click(function(){
        if (confirm('Are you sure you want to delete this marker?')) {
            $(this).parent().parent().parent().parent().remove();
            return false;
          }
        });
      // Edit button
      markers.find('.edit').click(function(){
          currentMarker = $(this).parent().parent().parent().parent().attr('id');
          markerDialog.find('#marker_title').val($('#markers #'+currentMarker,obj).find('a span strong').text());
          markerDialog.find('#marker_subtitle').val($('#markers #'+currentMarker,obj).find('a span em').text());
          classOptions = '';
          $('#legend a', obj).each(function(){
              classOptions = classOptions + '<option value="' + $(this).attr('class') + '" '+ (($('#markers #'+currentMarker,obj).attr('class')===$(this).attr('class')) ? 'selected="selected"':'') +'>' +
              $(this).attr('class')+ '</option>';
            });
          markerDialog.find('#marker_class').html(classOptions);
          markerDialog.find('#marker_link').val($('#markers #'+currentMarker,obj).find('a').attr('href'));
          markerDialog.find('#marker_open').attr('checked',($('#markers #'+currentMarker,obj).find('a').hasClass('open') ? 'checked' : '' ) );
          markerDialog.show();
        });
    }

  });  
 };  
})(jQuery); 


$(document).ready(function() {

    $('#slideshow').slideshow();
    
    $('#quotes-slideshow').cycle({random: true, timeout: 5000});
    
    $('.OraTableBorder #map').mapeditor();
    
    $('#map #legend a').toggle(
      function() {
        $('#markers li.'+$(this).attr('class')).hide();
        $(this).find('span').addClass('off');
      },
      function() {
        $('#markers li.'+$(this).attr('class')).show();       
        $(this).find('span').removeClass('off');
      }
    );

});







