$(document).ready(function() {


  //include jQuery.js --  visit: http://jquery.com/
  
  function gethiz (){
$(function(){
    maxZ = Math.max.apply(null,$.map($('.window'), function(e,n){
           if($(e).css('position')=='absolute')
                return parseInt($(e).css('z-index'))||1 ;
           })
    );
    return maxZ;
});
  }





/*
 // hides the slickbox as soon as the DOM is ready
 // (a little sooner than page load)
  $('#window').hide();
 // shows the slickbox on clicking the noted link
  $('a#slick-show').click(function() {
	
 $('#window').show('slow');
 return false;
  });
 // hides the slickbox on clicking the noted link
  $('a#collapse').click(function() {
 $('.window').hide('fast');
 return false;
  });
 // toggles the slickbox on clicking the noted link
  $('a#windowtoggle').click(function() {
 $('#window').toggle(400);
	    var z1 = parseInt($('#window').css('z-index'));
	  var z2 = parseInt($('#window2').css('z-index'));
	  var z3 = parseInt($('#window3').css('z-index'));
	  var z4 = parseInt($('#window4').css('z-index'));
	  var z5 = parseInt($('#window5').css('z-index'));
	  console.log(z1+' - '+z2+' - '+z3+' - '+z4+' - ');
	  
	  if(z1 < z2){
		  var z1 = z2++;
	}else if(z1 < z3){
		  var z1 = z3++;
	}else if(z1 < z4){
		  var z1 = z4++;
	}else if(z1 < z5){
		  var z1 = z5++;
	}
	$('#window').css('z-index', z1);
	
 return false;
  });
  
  
  
  
 // hides the slickbox as soon as the DOM is ready
 // (a little sooner than page load)
  $('#window2').hide();
 // shows the slickbox on clicking the noted link
  $('a#slick-show2').click(function() {
 $('#window2').show('slow');
 return false;
  });
 // hides the slickbox on clicking the noted link
  $('a#collapse2').click(function() {
 $('#window2').hide('fast');
 return false;
  });
 // toggles the slickbox on clicking the noted link
  $('a#windowtoggle2').click(function() {
 $('#window2').toggle(400);
	    var z1 = parseInt($('#window').css('z-index'));
	  var z2 = parseInt($('#window2').css('z-index'));
	  var z3 = parseInt($('#window3').css('z-index'));
	  var z4 = parseInt($('#window4').css('z-index'));
	  var z5 = parseInt($('#window5').css('z-index'));
	  console.log(z1+' - '+z2+' - '+z3+' - '+z4+' - ');
	  
	  if(z2 < z1){
		  var z2 = z1++;
	}else if(z2 < z3){
		  var z2 = z3++;
	}else if(z2 < z4){
		  var z1 = z4++;
	}else if(z2 < z5){
		  var z2 = z5++;
	}
	$('#window').css('z-index', z2);
	
 return false;
  });
  
  
  
  
 // hides the slickbox as soon as the DOM is ready
 // (a little sooner than page load)
  $('#window3').hide();
 // shows the slickbox on clicking the noted link
  $('a#slick-show3').click(function() {
 $('#window3').show('slow');
 return false;
  });
 // hides the slickbox on clicking the noted link
  $('a#collapse3').click(function() {
 $('#window3').hide('fast');
 return false;
  });
 // toggles the slickbox on clicking the noted link
  $('a#windowtoggle3').click(function() {
 $('#window3').toggle(400);
 return false;
  });
  
  
  
  
 // hides the slickbox as soon as the DOM is ready
 // (a little sooner than page load)
  $('#window4').hide();
 // shows the slickbox on clicking the noted link
  $('a#slick-show4').click(function() {
 $('#window4').show('slow');
 return false;
  });
 // hides the slickbox on clicking the noted link
  $('a#collapse4').click(function() {
 $('#window4').hide('fast');
 return false;
  });
 // toggles the slickbox on clicking the noted link
  $('a#windowtoggle4').click(function() {
 $('#window4').toggle(400);
 return false;
  });
  
  
  
  
 // hides the slickbox as soon as the DOM is ready
 // (a little sooner than page load)
  $('#window5').hide();
 // shows the slickbox on clicking the noted link
  $('a#slick-show5').click(function() {
 $('#window5').show('slow');
 return false;
  });
 // hides the slickbox on clicking the noted link
  $('a#collapse5').click(function() {
 $('#window5').hide('fast');
 return false;
  });
 // toggles the slickbox on clicking the noted link
  $('a#windowtoggle5').click(function() {
 $('#window5').toggle(400);
 return false;
  });
  
  
  
 // hides the slickbox as soon as the DOM is ready
 // (a little sooner than page load)
  $('#windowlm').hide();
 // shows the slickbox on clicking the noted link
  $('a#slick-showlm').click(function() {
 $('#windowlm').show('slow');
 return false;
  });
 // hides the slickbox on clicking the noted link
  $('a#collapselm').click(function() {
 $('#windowlm').hide('fast');
 return false;
  });
 // toggles the slickbox on clicking the noted link
  $('a#windowtogglelm').click(function() {
 $('#windowlm').toggle(400);
 return false;shads
 
 return false;
  });
  */
  
  
  
  
  
  $('#window').hide();
  $('#window2').hide();
  $('#window3').hide();
  $('#window4').hide();
  $('#window5').hide();
  
  $('#windowtoggleOver').hide();
  $('#windowtoggle2Over').hide();
  $('#windowtoggle3Over').hide();
  $('#windowtoggle4Over').hide();
  $('#windowtoggle5Over').hide();
 

//REDUCE CODE
/*
var i=0;
 for (i=0;i<=5;i++)
{
	console.log('#window'+i);
  $('#windowtoggle'+i).click(function(){
  $('#window'+i).fadeIn('500');
  });
  };*/
  
 
  //~ OPEN THE WINDOW
  $('#windowtoggle').click(function(){
   gethiz();
   var newZ = maxZ+1;
  $('#window').fadeIn('500');
	  var title = $(this).text();
	  $('.taskon').removeClass('taskon');

	  $('#taskitems').append('<div class="task taskon" id="task1">'+title+'</div>');	$('#windowtoggleOver').show();
 
	$("#window").topZIndex( { increment: 1 } );
  });
  
  
  
  $('#windowtoggle2').click(function(){
   gethiz();
   var newZ = maxZ+1;
  $('#window2').fadeIn('500');
	  var title = $(this).text();
	$('#windowtoggle2Over').show();
	  $('.taskon').removeClass('taskon');
	  $('#taskitems').append('<div class="task taskon" id="task2">'+title+'</div>');
 
	$("#window2").topZIndex( { increment: 1 } );
  });
  
  $('#windowtoggle3').click(function(){
   gethiz();
   var newZ = maxZ+1;
  $('#window3').fadeIn('500');
	  var title = $(this).text();
	$('#windowtoggle3Over').show();
	  $('.taskon').removeClass('taskon');

	  $('#taskitems').append('<span class="task taskon" id="task3">'+title+'</span>'); 
	$("#window3").topZIndex( { increment: 1 } );
  });
  
  $('#windowtoggle4').click(function(){
   gethiz();
   var newZ = maxZ+1;
  $('#window4').fadeIn('500');
	  var title = $(this).text();
	$('#windowtoggle4Over').show();
	  $('.taskon').removeClass('taskon');
	  $('#taskitems').append('<div class="task taskon" id="task4">'+title+'</div>');
 
	$("#window4").topZIndex( { increment: 1 } );
  });
  
  $('#windowtoggle5').click(function(){
   gethiz();
   var newZ = maxZ+1;
  $('#window5').fadeIn('500');
	  var title = $(this).text();
	$('#windowtoggle5Over').show();
	  $('.taskon').removeClass('taskon');
	  $('#taskitems').append('<div class="task taskon" id="task5">'+title+'</div>');
	  
 
	$("#window5").topZIndex( { increment: 1 } );
  });
  
  
  
  
  //~ CLOSE THE WINDOW
 $('a#collapse').click(function() {
 $('#window').fadeOut('300');
  $('#windowtoggleOver').hide();
	 $('#task1').remove();
 return false;
  });
  
   $('a#collapse2').click(function() {
 $('#window2').fadeOut('300');
	 $('#task2').remove();
	 $('#windowtoggle2Over').hide();
 return false;
  });
  
  $('a#collapse3').click(function() {
 $('#window3').fadeOut('300');
	 $('#task3').remove();
	 $('#windowtoggle3Over').hide();
 return false;
  });
  
   $('a#collapse4').click(function() {
 $('#window4').fadeOut('300');
	 $('#task4').remove();
	 $('#windowtoggle4Over').hide();
 return false;
  });
  
   $('a#collapse5').click(function() {
 $('#window5').fadeOut('300');
	 $('#task5').remove();
	 $('#windowtoggle5Over').hide();
 return false;
  });
  
  
  

  $('.task1').click(function(){
   $(this).topZIndex( { increment: 1 } );
	  $('.taskon').removeClass('taskon');
   $('#task1').addClass('taskon');
  });

  $('.task2').click(function(){
   $(this).topZIndex( { increment: 1 } );
	  $('.taskon').removeClass('taskon');
   $('#task2').addClass('taskon');
  });

  $('.task3').click(function(){
   $(this).topZIndex( { increment: 1 } );
	  $('.taskon').removeClass('taskon');
   $('#task3').addClass('taskon');
  });

  $('.task4').click(function(){
   $(this).topZIndex( { increment: 1 } );
	  $('.taskon').removeClass('taskon');
   $('#task4').addClass('taskon');
  });

  $('.task5').click(function(){
   $(this).topZIndex( { increment: 1 } );
	  $('.taskon').removeClass('taskon');
   $('#task5').addClass('taskon');
  });
  
  
  
  
  
$('.task').live('click', function() {

	  $('.taskon').removeClass('taskon');
   $(this).addClass('taskon');
 var thisid= $(this).attr('id');

 $('.'+thisid).topZIndex( { increment: 1 } );
 
if(  $('.'+thisid).is(":visible") == "true" ){
	 
	 }else{
		 $('.'+thisid).fadeIn('fast');
		 }
 
 //~ $('h4:contains('+thistitle+')').css('border','1px solid red');
 
  });
  
  $('.minibtn').click(function(){
	var theZ =  $(this).parent().css('z-index');
	  theZ = parseInt(theZ)-10;
	  $(this).parent().css('z-index', theZ);
	  $(this).parent().fadeOut('fast');
	  
	  });
  

  showtime();
  
  function showtime(){
	  
 var now = new Date();	  
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds();
	  if(hours <10){
		  hours = '0'+hours;
		  }else   if(minutes <10){
		  minutes = '0'+minutes;
		  }else   if(seconds <10){
		  seconds = '0'+seconds;
		  }
	  
	  
	  $('#clock').text(hours+':'+minutes);
timerID = setTimeout(function(){showtime();},1000);
	  }








$('#appright').load('includes/yellow.html');

$('#yellowapp').click(function(){
$('#appright').load('includes/yellow.html');
  });
$('#takeapp').click(function(){
$('#appright').load('includes/take.html');
  });
$('#ecommapp').click(function(){
$('#appright').load('includes/ecomm.html');
  });
$('#emarkapp').click(function(){
$('#appright').load('includes/emark.html');
  });
$('#salesapp').click(function(){
$('#appright').load('includes/sales.html');
  });
$('#netapp').click(function(){
$('#appright').load('includes/net.html');
  });
  
});











$(function() {

		//run the currently selected effect
		function runEffect(){
			//get effect type from 
			var selectedEffect = $('#effectTypes').val();
			
			//most effect types need no options passed by default
			var options = {};
			//check if it's scale, transfer, or size - they need options explicitly set
			if(selectedEffect == 'scale'){  options = {percent: 100}; }
			else if(selectedEffect == 'transfer'){ options = { to: "#button", className: 'ui-effects-transfer' }; }
			else if(selectedEffect == 'size'){ options = { to: {width: 280,height: 185} }; }
			
			//run the effect
			$("#effect").show(selectedEffect,options,500,callback);
		};
		
		//callback function to bring a hidden box back
		function callback(){
			setTimeout(function(){
				$("#effect:visible").removeAttr('style').hide().fadeOut();
			}, 1000);
		};
		
		//set effect from select menu value
		$("#button").click(function() {
			runEffect();
			return false;
		});
		
		$("#effect").hide();
	});
	
	
	// CEE BOX BIT
	
	 jQuery(document).ready(function(){
		debugging = true;

		$.fn.ceebox.videos.base.param.allowScriptAccess = "sameDomain" //added to kill the permissions problem
		$.extend($.fn.ceebox.videos,{
			uctv:{
				siteRgx: /uctv\.tv\/search\-details/i, 
				idRgx: /(?:showID=)([0-9]+)/i, 
				src: "http://www.uctv.tv/player/player_uctv_bug.swf",
				flashvars: {previewImage : "http://www.uctv.tv/images/programs/[id].jpg", movie : "rtmp://webcast.ucsd.edu/vod/mp4:[id]",videosize:0,buffer:1,volume:50,repeat:false,smoothing:true}
			}
		});
		//$().ceebox(); //used to test to make sure the init call works.
		//$(".ceebox").ceebox({boxColor:'#fff',borderColor:'#525252',textColor:'#333',videoJSON:"js/humor.json"});
		$(".ceebox").ceebox({titles:false, borderColor:'#dcdcdc',boxColor:"#fff"});
		//$("map").ceebox({fadeOut:"slow",fadeIn:"slow",onload:function(){$("#cee_box").animate({backgroundColor:"#F00"},function(){$(this).animate({backgroundColor:"#fff"})});}});		
		$("map").ceebox();		
		$(".ceebox2").ceebox({unload:function(){$("body").css({background:"#ddf"})}});
		//window.console.log($.fn.ceebox.videos.colbertFull)
		//$("body").ceebox(); //uncomment and every link on the page is in one gallery
		var testhtml = "<a href='http://balsaman.org' title='Balsa Man'>Balsa Man</a>"
		var testhtml2 = "<div style='padding:20px;text-align:center'><h2>Hi I am some content built as a javascript variable!</h2><p><a href='#' class='cee_close'>Close Me</a></p></div>"
		$("#testlink").click(function(){
			$.fn.ceebox.overlay();
			$.fn.ceebox.popup(testhtml,{onload:true,htmlWidth:600,htmlHeight:450});
			return false;		  
		});
		$("#testlink2").click(function(){
			$.fn.ceebox.overlay();
			$.fn.ceebox.popup(testhtml2,{width:600,height:400});
			return false;
		});
		//$.fn.ceebox.popup(testhtml,{onload:true,htmlWidth:600,htmlHeight:450});
	});
	
	
	
	
	
	
	
	
	
$(function() {
		$("#window").draggable({handle:'h4', stack:".stack"});
		$("div.h4").disableSelection();
		$("#window2").draggable({handle:'h4', stack:".stack"});
		$("div.h4").disableSelection();
		
		
		$("#window3").draggable({handle:'h4', stack:".stack"});
		$("div.h4").disableSelection();
		
		
		$("#window4").draggable({handle:'h4', stack:".stack"});
		$("div.h4").disableSelection();
		
		
		$("#window5").draggable({handle:'h4', stack:".stack"});
		$("div.h4").disableSelection();
		
		
		$("#window").draggable({ containment: '#containment-wrapper', scroll: false });
		$("#window2").draggable({ containment: '#containment-wrapper', scroll: false });

	});
	
	
	
	
	
	
