// Initialize all of the jQuery methods
$(document).ready(function () {

 	$("#loginForm").validate(); 

	$("#accountForm").validate(); 

	$("#post_live_date").datepicker({altFormat:'yy-mm-dd'});
	
	$("#post_live_time").clockpick({valuefield: 'post_live_time', useBgiframe: true, military: true, starthour: 1, endhour:23, showminutes: true, minutedivisions: 12});



	/* Admin - Featured Section */
	$(".product").draggable({revert: true});

	$("#featured_1").droppable({
		drop: function(event, ui) {
			
			$.getJSON(site_url+"/ajax.php", {"s" : "admin", "m" : "updateFeaturedListItem", "featured_item": "1", "product_id": $(ui.draggable).attr('id').replace("product_", "")}, function(data) {

				if (data.title != '') { $("#featured_1").html("&nbsp;"+data.title); $("#error_message").html("Update completed successfully."); } 
				
				else if (data.error_message != "") {
					
					$("#error_message").html(data.error_message);
					
				}

				if (data.featured_clear > 0) {
					
					$("#featured_"+data.featured_clear).html("&nbsp;");
					
				}

			});
		}
	});

	$("#featured_2").droppable({
		drop: function(event, ui) {

			$.getJSON(site_url+"/ajax.php", {"s" : "admin", "m" : "updateFeaturedListItem", "featured_item": "2", "product_id": $(ui.draggable).attr('id').replace("product_", "")}, function(data) {

				if (data.title != '') { $("#featured_2").html("&nbsp;"+data.title); $("#error_message").html("Update completed successfully."); } 
				
				else if (data.error_message != "") {
					
					$("#error_message").html(data.error_message);
					
				}
				
				if (data.featured_clear > 0) {
					
					$("#featured_"+data.featured_clear).html("&nbsp;");
					
				}
			
			});

		}
	});

	$("#featured_3").droppable({
		drop: function(event, ui) {

			$.getJSON(site_url+"/ajax.php", {"s" : "admin", "m" : "updateFeaturedListItem", "featured_item": "3", "product_id": $(ui.draggable).attr('id').replace("product_", "")}, function(data) {

				if (data.title != '') { $("#featured_3").html("&nbsp;"+data.title); $("#error_message").html("Update completed successfully."); } 
				
				else if (data.error_message != "") {
					
					$("#error_message").html(data.error_message);
					
				}
				
				if (data.featured_clear > 0) {
					
					$("#featured_"+data.featured_clear).html("&nbsp;");
					
				}
			
			});

		}
	});

	$("#featured_4").droppable({
		drop: function(event, ui) {

			$.getJSON(site_url+"/ajax.php", {"s" : "admin", "m" : "updateFeaturedListItem", "featured_item": "4", "product_id": $(ui.draggable).attr('id').replace("product_", "")}, function(data) {

				if (data.title != '') { $("#featured_4").html("&nbsp;"+data.title); $("#error_message").html("Update completed successfully."); } 
				
				else if (data.error_message != "") {
					
					$("#error_message").html(data.error_message);
					
				}
				
				if (data.featured_clear > 0) {
										
					$("#featured_"+data.featured_clear).html("&nbsp;");
					
				}
			
			});

		}
	});

	$("#featured_5").droppable({
		drop: function(event, ui) {

			$.getJSON(site_url+"/ajax.php", {"s" : "admin", "m" : "updateFeaturedListItem", "featured_item": "5", "product_id": $(ui.draggable).attr('id').replace("product_", "")}, function(data) {

				if (data.title != '') { $("#featured_5").html("&nbsp;"+data.title); $("#error_message").html("Update completed successfully."); } 
				
				else if (data.error_message != "") {
					
					$("#error_message").html(data.error_message);
					
				}
				
				if (data.featured_clear > 0) {
										
					$("#featured_"+data.featured_clear).html("&nbsp;");
					
				}
			
			});

		}
	});

	/*  jQuery plugin for TinyMCE Implementation */
	$('#cdescription').tinymce({

		// Location of TinyMCE script
		script_url : site_url+'includes/js/tiny_mce/tiny_mce.js',
 
		// General options
		theme : "advanced",
		plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",

		// Added HTML Elements (28-09-2009 scott@scottdouglas.ca)
		extended_valid_elements : "iframe[src|width|height|name|align|scrolling|style]",

		// Theme options
		theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
		theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
		theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
		theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true,

		// Example content CSS (should be your site CSS)
		content_css : "css/content.css",
		
		// Stop the damn <p> tags!!!
		forced_root_block : "",
 
		// Drop lists for link/image/media/template dialogs
		template_external_list_url : "lists/template_list.js",
		external_link_list_url : "lists/link_list.js",
		external_image_list_url : "lists/image_list.js",
		media_external_list_url : "lists/media_list.js",
 
		// Replace values for the template plugin
		template_replace_values : {
		username : "Some User",
		staffid : "991234"
		}

	});
	
	// This is to fix the width issue with the CSS page
	//
	// If the user is NOT using IE, it adds a bit of extra space
	if (!$.browser.msie) {
		$(".colmask").css({"width": "103.95%"});
	}

});

function view_course(product_id, name) {

	var viewer = window.open('/includes/assets/'+product_id+'/'+name+'/player.html', 'chs_viewer', 'status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=0,scrollbars=0,width=980,height=640');
	
}

function var_dump(obj) {

   if(typeof obj == "object") {
      return "Type: "+typeof(obj)+((obj.constructor) ? "\nConstructor: "+obj.constructor : "")+"\nValue: " + obj;
   } else {
      return "Type: "+typeof(obj)+"\nValue: "+obj;
   }
}//end function var_dump

