/* --------------------------------------------------------------------
// Author: Patrick Forringer ( patrick@forringer.com )
// File info: JS for H&M site
// Ver: 0.1
// Last modified: 11-16-09
//
*/
$().ready(function(){


	
	
	// Admin menu page functionality
	if( $('#admin_menu') ){
		
		
		// --------------------------------------------------------
		// Functionality for admin menu
		//
		
		function addNewItem_html( cat, rand ) {
		
		anim_speed = 500;
		
			return '<li new_item_for="'+ rand +'" class="new_item_cat">' +
				'<label for="itemName">Name:</label> <input type="text" name="itemName[]" value="New Item" class="name" />' +
				'<label for="itemSort">Sort:</label> <input type="text" name="itemSort[]" value="1" size="3" class="sort" />' +
				'<label for="itemDescription">Description:</label> <textarea name="itemDescription[]" class="descrip">New Item Description</textarea>'+
				'<label for="itemPrice">Price:</label> <input type="text" name="itemPrice[]" value="Price" class="price" />' +
				'<label for="itemImage">Image:</label> <input type="text" name="itemImage[]" value="" class="img" />' +
				'<input type="hidden" name="itemIds[]" value="" />'+
				'<input type="hidden" name="itemCats[]" value="'+cat+'" />'+
				'<span class="deleteItemLink"><a href="#">Delete Item</a></span>'+
			'</li>';
		}

		// --------------------------------------------------------
		//  Search bar text
		//	
/*
		var autofillop = {
			value: 'Enter data',
			toValue: '',
			defaultTextColor: '#777',
			activeTextColor: '#222'
		}
		
		$('.new_item_cat input, .new_item_cat textarea').autofill(autofillop);
*/
	
		$('.addItemLink a').click(function(){
						
			var cat_id = $(this).attr('num');
						
			$parent_ul = $('.item_list[cidnum='+cat_id+']');
			
			var rand = Math.random(3);
			
			$new_li = $parent_ul.append( addNewItem_html( cat_id, rand) ).find('li[new_item_for='+rand+']');
						
			$new_li.hide().height(0).slideDown(anim_speed); //.fadeIn(anim_speed)
			
			//$('.new_item_cat input, .new_item_cat textarea').autofill(autofillop);
			
			// stop click hash action
			return false;
			
		});
	
		// remove new item
		$('li[new_item_for] span.deleteItemLink a').live('click',function(){
			
			$(this).parent().parent().slideUp( anim_speed,function(){
				$(this).remove();
			})			
			
			return false;
		});
		
	
	
	// autofill add url form
	//	$('.new_item_cat input').autofill(autofillop);
		
	}
	
	if( $('.template_page') ){
		
		$('.template_page label input[checked]').parent().addClass('selected');
		
		$('.template_page label').click(function(){
		
			$('.template_page label').removeClass('selected');
			
			$(this).toggleClass('selected');
			
		});
					
	}
		
	
});