// Admin tabs plugin
(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;
	  });
  };
})();


$(document).ready(function() {
   
	$(".media").media({autoplay: true, width: 320, height: 212});
	$('.show_media').hide();
	$('.enable_preview').click(function(){    
		$('.show_media').hide(); 
		  $('#media-'+$(this).attr('rel')).toggle();
	});
	
	$('a.lightbox').lightBox();
	
	$('#sdrdn').change(function () 
	{
	   $('#sform').attr('action',$(this).val());
	});
	
	$('.load_register').click(function () 
	{
		$('#jqregister').jqmShow();
	});
	
	$('.load_window').click(function () 
	{
		rel = $(this).attr('rel');
		
		$('#'+rel).jqmShow();
	});
	
	$('.terms_and_conditions').click(function () 
	{
		if ($(this).attr('checked'))
		{
			$('#confirmed_terms').val('1');
		}
		else
		{
			$('#confirmed_terms').val('');
		}
	});
	
	$('.test_tracking').click(function () 
	{
		
		/*$.get("/pages_actions/check_cookies.php", function(data){
			if (data == 'enabled')
			{*/
				$(this).hide();            
				$('.cookie_test_text').hide();            
				$('.cookies_enabled').fadeIn();

				/*$('.cookies_disabled').hide();
			}
			else
			{
				$('.cookies_enabled').hide();
				$('.cookies_disabled').show();
			}
		});*/
	});
	
	$('.showhide').click(function() {
		if ($(this).hasClass('shreview'))
		{
			$(this).hide();
		}
		rel = $(this).attr('rel');
		if ($('#'+rel).css('display') == 'none')
		{
			$('#'+rel).show();
		}
		else
		{
			$('#'+rel).hide();
		}
	});
	
	$.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").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='';
				}
			}
		});
	});
	
	function serialize(s)
	{
		serial = $.SortSerialize(s);
		alert(serial.hash);
	};    
	
	$('.blackout').click(function() 
	{
		if ($('#blackout').css('display') == 'none')
		{
			$('#blackout').fadeIn();
			$('#blackout2').fadeIn();
			$('body').css('overflow','hidden');			
		}
		else
		{
			$('#blackout').fadeOut();
			$('#blackout2').fadeOut();
			$('body').css('overflow','auto');
		}
	});
	
	
	
 });
 
 