function serialize(s)
    {
        serial = $.SortSerialize(s);
        alert(serial.hash);
    };    
    
    $('.toggleLink').click(function(e){
      e.preventDefault();
      $(this.hash).slideToggle();
    });             
 
  function updateHiddenField(field,theValue){
    $('#'+field).val(theValue).change();
  }
    
function bookmark(address,sitename) {
  if (window.sidebar) {
    window.sidebar.addPanel(sitename, address,"");
  } else if( document.all ) {
    window.external.AddFavorite(address, sitename);
  } else if( window.opera && window.print ) {
    return true;
  }
}

function popUp(URL) {
  day = new Date();
  id = day.getTime();
  eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=800,height=700,left = 440,top = 250');");
}
        
function GetValueFromChild(myVal)
{
  document.getElementById('cms_templates_id').value = myVal;
}

$(document).ready(function() {
    $('a.confirm').click(function(e){
        e.preventDefault();
        $(this).after('<div class="confirm_dialog" id="DelDialog" style="display:none"><p></p></div>');
        var path = this.href;
        var dialog = $(this).siblings('.confirm_dialog');
        dialog.attr('title',this.title);
        dialog.children().text('Do you want to delete ' + this.rel + '?');
        dialog.dialog({
        resizable: false,
        height:140,
        modal: true,
        overlay: {
          backgroundColor: '#000',
          opacity: 0.5
        },
        buttons: {
            'Delete': function() {
              document.location = path;
            },
            Cancel: function() {
                $(this).dialog('close');
                $(this).remove();
                $('.confirm_dialog').remove();
            }
        }
        });
        $('.ui-dialog-content').show();
    });
    
    $('a.confirmaccept').click(function(e){
        e.preventDefault();
        $(this).after('<div class="confirm_dialog" id="DelDialog" style="display:none"><p></p></div>');
        var path = this.href;
        var dialog = $(this).siblings('.confirm_dialog');
        dialog.attr('title',this.title);
        dialog.children().text('Do you want to accept ' + this.rel + '?');
        dialog.dialog({
        resizable: false,
        height:140,
        modal: true,
        overlay: {
          backgroundColor: '#000',
          opacity: 0.5
        },
        buttons: {
            'Accept': function() {
              document.location = path;
            },
            'Cancel': function() {
                $(this).dialog('close');
                $(this).remove();
                $('.confirm_dialog').remove();
            }
        }
        });
        $('.ui-dialog-content').show();
    });
      $('#a_toggle').click(function(){$('#CMS-ANNOUNCEMENTS').slideToggle();});                                                
      $('#a_infoToggle').click(function(){$('#imageInfo').slideToggle();});
      
      $('a[rel=lightbox]').lightBox();
  
    $('.date-pick').datepicker({dateFormat:'dd/mm/yy',  yearRange: "-90:+15"});

	 // $('#profile_tabs > ul.tabs').tabs({ fxFade: true, fxSpeed: 'fast' });    
	//$('a[@rel*=lightbox]').lightBox(); // Select all links that contains lightbox in the attribute rel
																			  
	/*															 
	$('a.show_month').click(function(){
		$('a.show_month').removeClass('active');
		$('a.show_month').parent().removeClass('active');
		$(this).addClass('active');              
		$(this).parent().addClass('active');
		$('.the_months').hide();
		//alert(this.rel);
		$('div'+this.rel).fadeIn('fast');
	});     */
	$("a#show_flash_map").click(function() {
      if($('div#flash_map').css('display') == 'none'){
		$('div#flash_map').show();  
        $('#MapExpand').hide();
        $('#MapCollapse').show();
      } else {
		$('div#flash_map').hide();
        $('#MapCollapse').hide();
        $('#MapExpand').show();
      }
      
      /*var s1 = new SWFObject("/_ui/flash/flash_map.swf","flash_map","960","400","8");
      s1.addParam("allowfullscreen","true");
      s1.addVariable("width","960");
      s1.addVariable("height","400");                                                               
      s1.write("container");*/
	}); 
	
	$(".DashboardSettings").click(function() {
	   $('#DashboardSettings').slideToggle("slow");
	});
	
	$(".add_to_addressbook").click(function() {
	   $('#add_to_addressbook').slideToggle("slow");
	});
	$(".create_album").click(function() {
	   $('#create_album').slideToggle("slow");
	});
	
	$(".menu_toggle").click(function() {
		$('.'+$(this).attr('id')).slideToggle();
	});
								 
	
	$("#view_map").click(function() {
	   $('#map_container').slideToggle();
	   if($("#view_map").html() != 'Close Map')
	   {
			$("#view_map").html('Close Map');
	   }
	   else
	   {
			$("#view_map").html('View on Map');
	   }
	});
	$(".send_message").click(function(e) {
	   e.preventDefault();
	   $('#send_message').slideToggle("slow");
	   $('#invite_to_group').hide();
	   $('#add_a_note').hide();
	});
	$(".invite_to_group").click(function(e) {
	   e.preventDefault();
	   $('#invite_to_group').slideToggle("slow");
	   $('#send_message').hide();
	   $('#add_a_note').hide();
	});
	$(".add_a_note").click(function(e) {
	   e.preventDefault();
	   $('#add_a_note').slideToggle("slow");
	   $('#invite_to_group').hide();
	   $('#send_message').hide();
	}); 
	
	$(".media").media({autoplay: true, width: 500, height: 350});
	$('.show_media').hide();
	$('.enable_preview').click(function(e){
	   e.preventDefault();
		$('.show_media').hide(); 
		  $('#media-'+$(this).attr('rel')).slideToggle();
	});
	$('.close_pane').click(function(e){
	   e.preventDefault();
	   $(this).parents('.show_media').slideUp();
	});
	$('.show_send').click(function(e){
	   e.preventDefault();
	   $('#send_form').toggle();
	});
	$('.show_create_category').click(function(e){
	   e.preventDefault();
	   $('#create_category').toggle();
	});
    $('.show_announce').click(function(e){
       e.preventDefault();
       $('#NewAnnouncement').toggle();
    });
	
	$.fn.media.defaults = { 
	preferMeta:    1,         // true if markup metadata takes precedence over options object 
	autoplay:      1,         // normalized cross-player setting 
	bgColor:       '#ffffff', // background color 
	params:        {},        // added to object element as param elements; added to embed element as attrs 
	attrs:         {},        // added to object and embed elements as attrs 
	flashvars:     {},        // added to flash content as flashvars param/attr 
	flashVersion:  '8',       // required flash version 
 
	// default flash video and mp3 player 
	// @see: http://jeroenwijering.com/?item=Flash_Media_Player 
	flvPlayer:     '/_ui/flash/mediaplayer.swf', 
	mp3Player:     '/_ui/flash/mediaplayer.swf', 
	 
	// Silverlight options 
	// @see http://msdn2.microsoft.com/en-us/library/bb412401.aspx 
	silverlight: { 
		inplaceInstallPrompt: 'true', // display in-place install prompt? 
		isWindowless:         'true', // windowless mode (false for wrapping markup) 
		framerate:            '24',   // maximum framerate 
		version:              '0.9',  // Silverlight version 
		onError:              null,   // onError callback 
		onLoad:               null,   // onLoad callback 
		initParams:           null,   // object init params 
		userContext:          null    // callback arg passed to the load callback 
	} 
}; 
	
	$("input:text, textarea, input:password").each(function(){
		if(this.value == '')
			this.value = this.title;
	});
	$("input:text, textarea, input:password").click(function(){
		if(this.value == this.title)
			this.value = '';
	});
	$("input:text, textarea, input:password").blur(function(){
		if(this.value == '')
			this.value = this.title;
	});
	$("input:image, input:button, button:submit, input:submit").click(function(){
		$(this.form.elements).each(function(){
			if(this.type =='text' || this.type =='textarea' || this.type =='password'){
				if(this.value == this.title && this.title != ''){
					this.value='';
				}
			}
		});
	});
    
    $("form").submit(function(){
        $(this.form.elements).each(function(){
            if(this.type =='text' || this.type =='textarea' || this.type =='password'){
                if(this.value == this.title && this.title != ''){
                    this.value='';
                }
            }
        });
    });
	
	$('a.closeEl').bind('click', toggleContent);
 
		

	  
	var toggleContent = function(e)
	{
		var targetContent = $('div.bgWrap', this.parentNode.parentNode);
		if (targetContent.css('display') == 'none') {
			targetContent.slideDown(300);
			$(this).html('[-]');
		} else {
			targetContent.slideUp(300);
			$(this).html('[+]');
		}
		return false;
	};    
	function serialize(s)
	{
		serial = $.SortSerialize(s);
		alert(serial.hash);
	};    
	
	
 });
		 
         (function() {
  jQuery.fn.prevWrap = function(){
    var prev = jQuery(this).prev();
    if(prev.length) return prev;
    return jQuery(this).siblings().filter(':last-child');
  };
  jQuery.fn.nextWrap = function(){
    var next = jQuery(this).next();
    if(next.length) return next;
    return jQuery(this).siblings().filter(':first-child');
  };
})();

(function() {
  jQuery.fn.i3Tabs = function(){
      var container = $(this);
      var tabHeaders = container.children('.mainTabs').children('li');
      var tabs = container.find('.MSTabs_container');
      tabs.hide();
      tabHeaders.children('a').click(function(e){
        e.preventDefault();
        tabHeaders.removeClass('active');
        jQuery(this).parent().addClass('active');
        tabs.filter('.active').hide().removeClass('active');
        jQuery(this.hash).addClass('active').show();
      });
      var current = tabHeaders.filter('.active');
      if(current.length)
      {
        jQuery(current).children('a').click();
      } else {
        tabHeaders.filter(':first-child').children('a').click();
      }
      // Add scrolling
      container.children('.mainTabs').wheel(function(e,d){
        if(d>0)
        {
          tabHeaders.filter('.active').prevWrap().children('a').click();
        }
        else
        {
          tabHeaders.filter('.active').nextWrap().children('a').click();
        }
        return false;
      });
  };
        
    $('a','div.banner').attr('target','_blank'); 
    $('div.banner').click(function(){
        $.post('/pages_actions/cms_banner_click.php',{id: $(this).attr('rel')});  
    });
        
})();
	/*$(function()
{

$('a.confirm').confirm({
  timeout:3000,
  dialogShow:'fadeIn',
  dialogSpeed:'slow',
  buttons: {
	wrapper:'<button></button>',
	separator:'  '
  }  
  });
  });*/