$(document).ready(function(){
	
	$("#orderedlist li:list").hover(function() {
	     $(this).addClass("green");
	   },function(){
	     $(this).removeClass("green");
	 });

	 $(document).ready(function() {
	   $("#ul-test > li").addClass("blue");
	 });

	 $("#ul-test").find("li").each(function(i) {
	     $(this).append( " BAM! " + i );
	 });
	
	
	// generate markup
	   $("#rating").append("Please rate: ");
	   
	   for ( var i = 1; i <= 5; i++ )
	     $("#rating").append("<a href='#'>" + i + "</a> ");
	   
	   // add markup to container and apply click handlers to anchors
	   $("#rating a").click(function(e){
	     // stop normal link click
	     e.preventDefault();
	     
	     // send request
	     $.post("rate.php", {rating: $(this).html()}, function(xml) {
	       // format and output result
	       $("#rating").html(
	         "Thanks for rating, current average: " +
	         $("average", xml).text() +
	         ", number of votes: " +
	         $("count", xml).text()
	       );
	     });
	   });
	   
	   //################# Hide-show example 
	   
	   $("#hideit").click(function () {
		      $("#hidethis").hide();
			   $.get("jquery_text/donotuse.html");
		      return false;
	    });
	   
	   $("#showit").click(function () {
		      $("#hidethis").show();
		      return false;
		    });

	   //################# Slide-up example ################################ 
	   
	   $("#mybutton p").click(function () {
		   $(this).slideUp(); 
	    });

	   $("p#mybutton2").click(function () {
		   $(this).slideUp(); 
	    });
	   
	   //################# Image radio exmaple ################################ 
	   // Image Selection related  
	   $("input#option").val("none");
	   $("a#submit").click(function (e) {

		   var value = $("input#option").val();
		   if (value == "none" ){
			   alert("ddd");
			   e.preventDefault();
			   return;
		   }
		   
		   var value = $("select#selectDown").val();
		   alert(value);
		   if (value == "1" ){
			   alert("dddd");
			   e.preventDefault();
			   return;
		   }
		   
	    });	   
	   
	   $("table#buttontable td#tdoption1").click(function () {
		   $("table#buttontable #tdoption2").removeClass("option-selected"); 
		   $("table#buttontable #tdoption2").addClass("option-unselected"); 
		   $("table#buttontable #tdoption1").addClass("option-selected");
		   $("input#option").val("option1");
	    });

	   $("table#buttontable td#tdoption2").click(function () {
		   $("table#buttontable #tdoption1").removeClass("option-selected"); 
		   $("table#buttontable #tdoption1").addClass("option-unselected");
		   $("table#buttontable #tdoption2").addClass("option-selected"); 
		   $("input#option").val("option2");
	    });
	   //################# AJAX exmaple ################################ 

	   $("#getit").click(function () {
		     // send request
		     $.get("jquery_text/donotuse.html", function() {
		       // format and output result
		       $("#resp").html("Thanks for rasting, current average: ");
		     });
		      return false;
	    });

	   $("#getit2").click(function () {
		     // send request
		     $.get("jquery_text/donotuse.html", function(xml) {
		       // format and output result
			       $("#resp2").html("<img src=\"/images/icons/32px-Crystal_Clear_action_view_bottom.png\"/>Thanks for rasting, current average: " + $("result", xml).text()).hide().fadeIn(1500);
			       $("#resp_out").html("Thanks for rasting, current average: " + $("result", xml).text()).hide().fadeIn(1500);
		     });
		      return false;
	    });
	   
	 //################# AJAX exmaple ################################
	   
	 //for each description div...
		$('div.description').each(function(){
			//...set the opacity to 0...
			$(this).css('opacity', 0);
			//..set width same as the image...
			$(this).css('width', $(this).siblings('a').find('img').width());
			//...get the parent (the wrapper) and set it's width same as the image width... '
			$(this).parent().css('width', $(this).siblings('img').width());
			//...set the display to block
			$(this).css('display', 'block');
			
			//alert($(this).siblings('a').find('img').width());
		});
		
		$('div.wrapper').hover(function(){
			//when mouse hover over the wrapper div
			//get it's children elements with class descriptio
			//and show it using fadeTo
			$(this).children('.description').stop().fadeTo(500, 0.6);
		},function(){
			//when mouse out of the wrapper div
			//use fadeTo to hide the div
			$(this).children('.description').stop().fadeTo(500, 0);
		});

		 //################# AJAX exmaple ################################
   		   $("#wait").hide(); 
	 		$("#loadcontent").hide();
		   $("#getit3").click(function () {
			   
			     // send request
			     $.ajax({
			    	type: "GET",
			     	url: "/jquery_text/donotuse.html",
			     	data: "data=true",
			     	beforeSend: function() { 
			    	 		$("#loadcontent").hide();
  		    	   		   $("#getit3-wrapper").hide(); 
			    	 		$("#wait").show(); 
			    	 },
			     	complete: function() { 
			    	 			$('#wait').hide(); 
			    	 },
			     	success: function(text) {
	    	   		   $("#getit3-wrapper").show(); 
			     		$("#loadcontent").show("slow");
			     		$("#loadcontent").html(text);
			     	}
			     })
			     
   	   		   $('#getit3').show(); 

			     return false;
		    });
		   
		   //################# AJAXIFY exmaple ################################
			$('.ajaxify').ajaxify();
			$('a#options').ajaxify({
		              link:'/jquery_text/donotuse.html?data=true',
		              target: '#container',
		              loading_img:'images/wait.gif',
		              title:'Setting up options', // change page title. Since v2.0
		              method:'GET'});
			
			$('a#options2').ajaxify({
	              link:'/jquery_text/donotuse.html?random=true',
	              target: '#container2',
	              loading_img:'images/loader/arrows16.gif',
	              title:'Adding cart', // change page title. Since v2.0
	              method:'GET'});

			//################# FORM CHANGE exmaple ################################

		   $("#changetest").click(function () {
			   $("#empty").html('<a href="javascript:;" onclick="go();">Link text</a>').show("normal");
		   });
		   
		   $("#remove").click(function () {
			   $("#xxx").remove();
		   });
		   
		   //### TABS ##############
			// Tabs
			$('#mytabs').tabs();
			$('#mytabs2').tabs({ event: 'mouseover' });

			//################# Accordion Menu Sample ################################
			$("#accordion > li").hover(function(){

				if(false == $(this).next().is(':visible')) {
					$('#accordion > ul').slideUp(300);
				}
				$(this).next().slideToggle(300);
			});

			//$('#accordion > ul:eq(0)').show();

			 //################# Color box ################################
			//Examples of how to assign the ColorBox event to elements
			//$("a[rel='example1']").colorbox();
			//$("a[rel='example2']").colorbox({transition:"fade"});
			//$("a[rel='example3']").colorbox({transition:"none", width:"75%", height:"75%"});
			//$("a[rel='example4']").colorbox({slideshow:true});
			//$(".single").colorbox({}, function(){
			//	alert('Howdy, this is an example callback.');
			//});
			//$(".colorbox").colorbox();
			//$(".youtube").colorbox({iframe:true, width:650, height:550});
			//$(".iframe").colorbox({width:"80%", height:"80%", iframe:true});
			//$(".inline").colorbox({width:"50%", inline:true, href:"#inline_example1"});
			
			//Example of preserving a JavaScript event for inline calls.
			$("#click").click(function(){ 
				$('#click').css({"background-color":"#f00", "color":"#fff", "cursor":"inherit"}).text("Open this window again and this message will still be here.");
				return false;
			});
			
			//################# Fancy Box Example ##
			
			 /* This is basic - uses default settings */ 
			//$("a#single_image").fancybox(); /* Using custom settings */ 
			//$("a#inline").fancybox({ 'hideOnContentClick': true }); 
			//$("a.group").fancybox({ 'zoomSpeedIn': 100, 'zoomSpeedOut': 100, 'overlayShow': false }); 			
			//$("a.group").fancybox({ 'overlayShow': false });
			
			//################# JSON Example
			// return example from flickr
/*			
			jsonp1259853705249({
				"title": "Recent Uploads tagged cat",
				"link": "http://www.flickr.com/photos/tags/cat/",
				"description": "",
				"modified": "2009-12-03T15:11:26Z",
				"generator": "http://www.flickr.com/",
				"items": [
				   {
				"title": "The stuff on the piano...",
				"link": "http://www.flickr.com/photos/hulpy/4155015053/",
				"media": {"m":"http://farm3.static.flickr.com/2712/4155015053_a23fde9588_m.jpg"},
				"date_taken": "2009-12-01T20:02:50-08:00",
				"description": "<p><a href=\"http://www.flickr.com/people/hulpy/\">Hulpy (Carmen)<\/a> posted a photo:<\/p> <p><a href=\"http://www.flickr.com/photos/hulpy/4155015053/\" title=\"The stuff on the piano...\"><img src=\"http://farm3.static.flickr.com/2712/4155015053_a23fde9588_m.jpg\" width=\"240\" height=\"160\" alt=\"The stuff on the piano...\" /><\/a><\/p> ",
				"published": "2009-12-03T15:11:26Z",
				"author": "nobody@flickr.com (Hulpy (Carmen))",
				"author_id": "38510803@N06",
				"tags": "pictures cat photo frames chat foto photos tabby decoration picture gato fotos frame katze deco gatto kater rahmen pictureframe deko dekoration getigert bilderrahmen fotorahmen"
				   },
				   {
				"title": "IMG_1176",
				"link": "http://www.flickr.com/photos/ch3nks/4155012803/",
				"media": {"m":"http://farm3.static.flickr.com/2541/4155012803_72484940ba_m.jpg"},
				"date_taken": "2009-12-03T15:53:24-08:00",
				"description": "<p><a href=\"http://www.flickr.com/people/ch3nks/\">Ch3nks<\/a> posted a photo:<\/p> <p><a href=\"http://www.flickr.com/photos/ch3nks/4155012803/\" title=\"IMG_1176\"><img src=\"http://farm3.static.flickr.com/2541/4155012803_72484940ba_m.jpg\" width=\"240\" height=\"180\" alt=\"IMG_1176\" /><\/a><\/p> ",
				"published": "2009-12-03T15:10:20Z",
				"author": "nobody@flickr.com (Ch3nks)",
				"author_id": "23765769@N02",
				"tags": "cat"
				   }
				        ]
				})
*/			
			   //################# JSON exmaple ################################
			   
			$.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?tags=cat&tagmode=any&format=json&jsoncallback=?",
				function(data){
			       	$.each(data.items, function(i,item){
			       		$("<img width='100px'/>").attr("src", item.media.m).appendTo("#jsonimages");
			       		if ( i == 3 ) return false;
			       	});
			    });

			//alert("end");
			
			// ### CEEBOX
			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({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});

//			$('#create-user')
//			.button()
//			.click(function() {
//				$('#dialog-form').dialog('open');
//			});
			

			$("#picked").click(function(){
				document.getElementById("pickedval").value="xxx";
			});
//			alert('x');

			


			//################# jqModal Confirmation ################################

		  $('#confirm').jqm({overlay: 88, modal: true, trigger: false});
		  
		  // trigger a confirm whenever links of class alert are pressed.
		  $('a.confirm').click(function() { 
			  confirm('About to visit: '+this.href+' !',this.href); 
			  return false;
		  });
 });

function confirm(msg,callback) {
	  $('#confirm')
	    .jqmShow()
	    .find('p.jqmConfirmMsg')
	      .html(msg)
	    .end()
	    .find(':submit:visible')
	      .click(function(){
	        if(this.value == 'yes')
	          (typeof callback == 'string') ?
	            window.location.href = callback :
	            callback();
	        $('#confirm').jqmHide();
	      });
}

function mycallbackfunc(v,m,f){
	$.prompt('i clicked ' + v);
}

function removeUser2(id){
    
	var txt = 'Are you sure you want to remove this?<input type="hidden" id="userid" name="userid" value="'+ id +'" />';
	
	$.prompt(txt,{ 
		buttons:{Delete:true, Cancel:false},
		callback: function(v,m,f){
			if(v){
				var uid = f.userid;
				$.post("/linktoAction.html?", { id: uid, del: "true" },
						   function(data){
						     alert("Data Loaded: " + data);
						   });
			}
		}
	});
}




