if (window != top) top.location.href = location.href;
$slideshow = {
    context: false,
    tabs: false,
    timeout: 6000,      // time before next slide appears (in ms)
    slideSpeed: 1500,   // time it takes to slide in each slide (in ms)
    tabSpeed: 300,      // time it takes to slide in each slide (in ms) when clicking through tabs
    fx: 'fade',   // the slide effect to use
    pauseOH: true, //set to false to disable pause
    
    init: function() {
        // set the context to help speed up selectors/improve performance
        this.context = $('#slideshow');
        
        // set tabs to current hard coded navigation items
        this.tabs = $('#tabs li', this.context);
        
        // remove hard coded navigation items from DOM 
        // because they aren't hooked up to jQuery cycle
        this.tabs.remove();
        
        // prepare slideshow and jQuery cycle tabs
        this.prepareSlideshow();
    },
    
    prepareSlideshow: function() {
        // initialise the jquery cycle plugin -
        // for information on the options set below go to: 
        // http://malsup.com/jquery/cycle/options.html
        $("div.slides > ul", $slideshow.context).cycle({
            fx: $slideshow.fx,
            timeout: $slideshow.timeout,
            speed: $slideshow.slideSpeed,
            fastOnEvent: $slideshow.tabSpeed,
            pager: $("#tabs", $slideshow.context),
            pagerAnchorBuilder: $slideshow.prepareTabs,
            before: $slideshow.activateTab,
            pauseOnPagerHover: $slideshow.pauseOH,
            pause: $slideshow.pauseOH
        });            
    },
    
    prepareTabs: function(i, slide) {
        // return markup from hardcoded tabs for use as jQuery cycle tabs
        // (attaches necessary jQuery cycle events to tabs)
        return $slideshow.tabs.eq(i);
    },

    activateTab: function(currentSlide, nextSlide) {
        // get the active tab
        var activeTab = $('a[href="#' + nextSlide.id + '"]', $slideshow.context);
        
        // if there is an active tab
        if(activeTab.length) {
            // remove active styling from all other tabs
            $slideshow.tabs.removeClass('on');
            
            // add active styling to active button
            activeTab.parent().addClass('on');
        }            
    }            
};


$(function() {
/*
  var $s=$('#s');
  var searchLabel=$('#topSearch label').hide().text();
  function restoreSearch(){if($s.val()==''){$s.val(searchLabel);}
*/

  var $s = $('#s');
  var searchLabel = $('#topSearch label').hide().text();
  function restoreSearch() {
    if ($s.val() == '') {
      $s.val(searchLabel);
    }
  }
  
  restoreSearch();
  $s.focus(function(){
    if ($s.val() == searchLabel) {
      $s.val('');
    }
  }).blur(restoreSearch);  
  
  $('#tabs li:first').addClass('on');

  // initialise the slideshow when the DOM is ready
  $slideshow.init();
  
  $('#main ol li').css('font-weight', 'bold').wrapInner('<span></span>').children('span').css('font-weight', 'normal');
/*  
  $('#s').focus(function() {
    item = $(this);
    if (item.attr('value') == 'Search') {
      item.attr('value', '');
    } 
  })
  $('#s').blur(function () {
    item = $(this);
    if (item.attr('value') == '') {
      item.attr('value', 'Search');
    }
  });
*/
  // for ajax contact form
  if ($('#cf').attr('method')) {
    
      $('#cf').submit(function() {
  
        var inputs = [];
        $(':input', this).each(function() {
          inputs.push(this.name + '=' + escape(this.value));
          //alert('hi');
        });
        
        jQuery.ajax({
          data: inputs.join('&'),
          url: this.action,
          timeout: 2000,
          
          beforeSend: function() {
            $("#loader").html('<img src="/wp-content/themes/dts/images/ajax-loader.gif" alt="Sending Message..." />');
            $('input#sender').hide();
            $('.msg').fadeOut('fast');
          },
          success: function(r) {        
            $('input#sender').show();
            $("#loader").replaceWith('');
            $('#txtmsg').empty().append(r);
            $('.msg').css('display', 'block').fadeIn('slow');
          }
        });
        
        return false;
      })
  
  }
  
    

});

$(function() {
  $('#filterresults').change(
    function(){
      var str = "";
      str = $("#filterresults option:selected").attr('value');
      if( $("#admin_user option:selected").attr('value') != 0){
	    str1 = '&theuser=' + $("#admin_user option:selected").attr('value');
      } else {
      	str1 = '';
      }
      window.location = '/my-account/documents-files/?filterBy=' + str + str1;
    }
  );
});
/* Documents */

$(function() {
  $('#admin_user').change(
    function(){
      var str = "";
      str = $("#admin_user option:selected").attr('value');
      if( $("#filterresults option:selected").attr('value') != 0){
	    str1 = '&filterBy=' + $("#filterresults option:selected").attr('value');
      } else {
      	str1 = '';
      }
      window.location = '/my-account/documents-files/?theuser=' + str + str1;
    }
  );
});
/* Spreadsheet Manage */
$(function() {
  $('#admin_user_ssmanage').change(
    function(){

      if( $("#admin_user_ssmanage option:selected").attr('value') != 0){
        str = $("#admin_user_ssmanage option:selected").attr('value');
      } else {
        str = '';
      }
      str1 = '&monthview=' + $("select[name='monthview'] option:selected").attr('value');
      str2 = '&yearview=' + $("select[name='yearview'] option:selected").attr('value');
      window.location = '/my-account/spreadsheets/1/manage/?theuser=' + str + str1 + str2;
    }
  );
});
/* Spreadsheet Report */
$(function() {
  $('#admin_user_ssreport').change(
    function(){

      if( $("#admin_user_ssreport option:selected").attr('value') != 0){
        str = $("#admin_user_ssreport option:selected").attr('value');
      } else {
        str = '';
      }
      str1 = '&monthview=' + $("select[name='monthview'] option:selected").attr('value');
      str2 = '&yearview=' + $("select[name='yearview'] option:selected").attr('value');
      str3 = '&d1view=' + $("select[name='d1view'] option:selected").attr('value');
      str4 = '&d2v+iew=' + $("select[name='d2view'] option:selected").attr('value');

      window.location = '/my-account/spreadsheets/1/report/?theuser=' + str + str1 + str2 + str3 + str4;
    }
  );
});

/* Spreadsheet Export */
$(function() {
  $('#admin_user_ssexport').change(
    function(){

      if( $("#admin_user_ssexport option:selected").attr('value') != 0){
        str = $("#admin_user_ssexport option:selected").attr('value');
      } else {
        str = '';
      }
      str1 = '&monthview=' + $("select[name='monthview'] option:selected").attr('value');
      str2 = '&yearview=' + $("select[name='yearview'] option:selected").attr('value');
      window.location = '/my-account/spreadsheets/1/export/?theuser=' + str + str1 + str2;
    }
  );
});

/*!
* Duplicate / Remove: a jQuery Plugin
* @author: Trevor Morris (trovster)
* @url: http://www.trovster.com/lab/code/plugins/jquery.duplicate-remove.js
* @documentation: http://www.trovster.com/lab/plugins/duplicate-remove/
* @published: 06/10/2008
* @updated: 02/06/2009
* @license Creative Commons Attribution Non-Commercial Share Alike 3.0 Licence
*		   http://creativecommons.org/licenses/by-nc-sa/3.0/
*
*/
if(typeof jQuery != 'undefined') {
	jQuery(function($) {
		$.fn.extend({
			duplicate_remove: function(options) {
				var settings = $.extend({}, $.fn.duplicate_remove.defaults, options);

				return this.each(
					function() {
						var $$, o, $basic, $parent, total,
							$duplicate, $remove;
						
						$$ 		= $(this);
						o		= $.metadata ? $.extend({}, settings, $$.metadata()) : settings;
						$basic	= $$.clone();
						$parent	= $$.parent();
						total	= $parent.find($basic).length;
						
						$duplicate	= $('<a></a>').attr('href',o['duplicate']['href']).text(o['duplicate']['text']).addClass('duplicate').addClass('phark');
						$remove		= $('<a></a>').attr('href',o['remove']['href']).text(o['remove']['text']).addClass('remove').addClass('phark');
						
						$$.append($remove).append($duplicate);
		
						$$.find('a.duplicate').bind('click.duplicate', function(e){
							var $a;
							$a = $(this);
							if($a.is(':not(.forbidden)')) {
								$basic.clone().duplicate_remove(o).hide().insertAfter($$).slideDown(o['duplicate']['speed'], function(){
									$parent = $(this).parent();
									
									$remove_items 		= $parent.find('a[href='+o['remove']['href']+']');
									$duplicate_items 	= $parent.find('a[href='+o['duplicate']['href']+']');
									remove_total 		= $remove_items.length;
									duplicate_total 	= $duplicate_items.length;
									
									if(remove_total==1) {
										$remove_items.addClass('forbidden').addClass('remove-forbidden').attr('title', 'Disabled');
									}
									else {
										$remove_items.removeClass('forbidden').removeClass('remove-forbidden').attr('title', o['remove']['text']);
									}
									
									if(typeof o['limit'] != 'undefined' && o['limit']!==false && is_numeric(o['limit']) && duplicate_total>=o['limit']) {
										$duplicate_items.addClass('forbidden').addClass('duplicate-forbidden').attr('title', 'Disabled');
									}
									else {
										$duplicate_items.removeClass('forbidden').removeClass('duplicate-forbidden').attr('title', o['duplicate']['text']);
									}
									$(this).find('input').focus();
								});
							}
							
							$a.blur();
							return false;
						})
						$$.find('a.remove').bind('click.remove', function(e) {
							var $a;
							$a = $(this);
							if($a.is(':not(.forbidden)')) {
								$$.slideUp(o['remove']['speed'], function() {
									$parent = $(this).parent();
									$(this).remove();
									
									$remove_items 		= $parent.find('a[href='+o['remove']['href']+']');
									$duplicate_items 	= $parent.find('a[href='+o['duplicate']['href']+']');
									remove_total 		= $remove_items.length;
									duplicate_total 	= $duplicate_items.length;
									
									if(remove_total==1) {
										$remove_items.addClass('forbidden').addClass('remove-forbidden').attr('title','Disabled');
									}
									else {
										$remove_items.removeClass('forbidden').removeClass('remove-forbidden').attr('title',o['remove']['text']);
									}
									
									if(typeof o['limit'] != 'undefined' && o['limit']!==false && is_numeric(o['limit']) && duplicate_total>=o['limit']) {
										$duplicate_items.addClass('forbidden').addClass('duplicate-forbidden').attr('title','Disabled');
									}
									else {
										$duplicate_items.removeClass('forbidden').removeClass('duplicate-forbidden').attr('title',o['duplicate']['text']);
									}
								});
							}
							$a.blur();
							return false;
						});
						
						if(total < 2) {
							$$.find('a.remove').addClass('forbidden').addClass('remove-forbidden').attr('title','Disabled');
						}
						else {
							$$.find('a.remove.forbidden').removeClass('remove-forbidden').removeClass('forbidden').attr('title',o['remove']['text']);
						}
						
						if(typeof o['limit'] != 'undefined' && o['limit']!==false && is_numeric(o['limit']) && total>=o['limit']) {
							$$.find('a.duplicate').addClass('forbidden').addClass('duplicate-forbidden').attr('title','Disabled');
						}
						else {
							$$.find('a.duplicate').removeClass('forbidden').removeClass('duplicate-forbidden').attr('title',o['duplicate']['text']);
						}
					}
				);
			}
		});
		
		/**
		* Private Function
		* Checks whether a string is numeric
		*/
		function is_numeric(str) {
			var nums = '0123456789';
			if(str.length==0) return false;
			for(var n=0; n < str.length; n++) {
				if(nums.indexOf(str.charAt(n))==-1) return false;
			}
			return true;
		}
		
		/**
		* Plugin Defaults
		*/
		$.fn.duplicate_remove.defaults = {
			'duplicate' : {
				'text'	: 'Duplicate',
				'href'	: '#duplicate',
				'speed'	: 1000
			},
			'remove'	: {
				'text'	: 'Remove',
				'href'	: '#remove',
				'speed'	: 1000
			},
			'limit' : false
		};
	});
}

