$(document).ready(function() {
	$('div').pngFix();
	
	//Options dropdown
	$("#orderBy").click(function() {
		$(this).find("ul").show();					
	})

	$("#orderBy ul li a").click(function() {	
		optionText = $(this).html();
		setTimeout(function(){
			$("#orderBy ul").hide();
			$("#orderBy .optionName").html(optionText);
			
		},1);
	});

	$("#orderBy").mouseleave(function() {
		$(this).find("ul").hide();					
	});
	
	//Search box in the left nav
	$("#leftSearch").click(function() {
		if ($(this).val() == "SEARCH") {
			$(this).val("");
		}
	});
	
	$("#leftSearch").blur(function() {
		if ($(this).val() == "") {
			$(this).val("SEARCH");
		}
	});
	
	$("#uploaded_images .uploaded_image a").live('click', function() 
	{
		var indexarray = $(this).get(0).id.split("_");
		var index = indexarray[3];
		//alert('index :: ' + index);
		filenames.splice(index, 1);
		fileurls.splice(index, 1);
		
	    var hiddenfieldvalue = "";
	    var imagehtml = "";				             
	    for(var i=0;i<filenames.length;i++)
	    {
	    	if(i == filenames.length - 1)
	    	{
	    		hiddenfieldvalue += filenames[i];
	    	}
	    	else
	    	{
	    		var txt = filenames[i] + ",";
	    		hiddenfieldvalue += txt;
	    	}
	    	
	    	imagehtml += '<div class="uploaded_image"><img src="' + fileurls[i] + '" /><span><a href="remove_image" id="uploadify_image_thumb_' + i + '">X Remove</a></span></div>';
	    }
	    
	    imagehtml += '<div class="clear"></div>';

	    $("#images-uploadify_images").val(hiddenfieldvalue);
	    $("#uploaded_images").html(imagehtml);
	    
	    var queuelimit = $('#upload_container').uploadifySettings('queueSizeLimit');
	    queuelimit++;  
	    $('#upload_container').uploadifySettings('queueSizeLimit', queuelimit); 
	    return false;
	});
});
