$(function(){

	$("#gallery_sidebar input[type='text']").val("Search artists...").data("placeholder","Search artists...");
	
	$("#gallery_sidebar input[type='text']").focus(function(){
		if($(this).val()==$(this).data("placeholder")){
			$(this).val("");
		}
	});
	
	$("#gallery_sidebar input[type='text']").blur(function(){
		if($(this).val()==""){
			$(this).val($(this).data("placeholder"));
		}
	});
	

	
	$("p.caption").each(function(){
		$(this).width($(this).parent().find('img').width());
	});


	$(".upanddownlinks,.criteriumedit,.criteriumdelete,.additemlink,.galleryedit").remove();
	
	
	var isInputSupported = 'placeholder' in document.createElement('input');
	
	
	
		$("#main input:text").each(function(){
	
			var note = ($(this).parent().find('.inputnote').text());
	
					$(this).attr('placeholder',note);
					
				if(!isInputSupported){	
					
					$(this).focus(function(){
						if($(this).val()== $(this).attr('placeholder')){
							$(this).val('');
							$(this).removeClass('placeholder');
						}
					}).blur(function(){
						if($(this).val()==''){
							$(this).val($(this).attr('placeholder'));
							$(this).addClass('placeholder');
						}
					}).blur();
				
				}
	
				$(this).parent().find('.inputnote').remove();
	
				
	
		});
		$(".sliderimagewrapper .image_description").hide();
		
		
		$(".sliderimagewrapper .admin").hide();
		
		$(".sliderimagewrapper").mouseenter(function(){
		
			$(this).find(".admin").show();
			$(this).find(".image_description").show();
		
		});
		
		$(".sliderimagewrapper").mouseleave(function(){
		
			$(this).find(".admin").hide();
			$(this).find(".image_description").hide();
		});
	
	
	
	 $("#gallery_panel").parents("#content1").append("<div id='slider_controls' />");
	 $("#slider_controls").append("<a class='prev' id='gallery-prev' href='#'><span> « prev </span></a>");
	  $("#slider_controls").append("<a class='next' id='gallery-next' href='#'><span> next » </span></a>");

	 $("#gallery_panel li").css("float","left");
	 
	
	
		 
	 
	
	 $("h1.crumb").html($("h1.crumb").html().split("[copy]").join(""));
	
	 
	 $(".comments label").css({
	 	'text-align':'left',
	 	'float':'none'
	 });
	 
	 $("#antirobot1").css('display','none');
	 
	 $("#gallery_sidebar a").each(function(){
	 	$(this).html($(this).text().split("-").join(" "));
	 	if($(this).text()=="homefeature"){
	 		$(this).remove();
	 	}
	 });

	//Hide (Collapse) the toggle containers on load
	if($(".gallery_section #content0 .pageblocktext").size()>0){
	
		$(".gallery_section #content0 .pageblocktext,.gallery_section #content0 .imageholder").hide();
		$(".gallery_section #content0 .pageblocktext").show();
	
		var textLength = $(".gallery_section #content0 .pageblocktext").text().length;
		
		if(textLength>240){
			$(".gallery_section #content0 .pageblocktext").wrapInner("<span id='textsegment'></span>");
			$("#textsegment").html($("#textsegment").text().substring(0,240)+"</span><span id='textremainder'>"+$("#textsegment").text().substring(240));
			$("#textremainder").hide();
			makeReadMore($("#textsegment"));
		} else if ($(".gallery_section #content0 .pageblocktext").size()>1){
			makeReadMore($(".gallery_section #content0 .pageblocktext"));		
		}
		
		
		$(".gallery_section #content0 .pageblocks .pageblocktext, .gallery_section #content0 .pageblocks .page_subtitle").toggle(function(){
			$("#textremainder").show();
			$("#readmore").hide();
			$(this).parent().find(".imageholder,.pageblocktext").slideDown("slow");
			$(this).toggleClass("active");
		},function(){
			//$(this).parent().find(".imageholder,.pageblocktext").slideUp();
			$("#textremainder").hide();
			$("#readmore").show();
			
			$(this).toggleClass("active");
		});
	}


	
	


});

function makeReadMore(elementToAppendTo){
	elementToAppendTo.append("<span id='readmore'>Read more...</span>");
	$("#readmore").css({
				"color":"#EF3D4D",
				"text-decoration":"underline",
				"padding-left":"5px",
				"font-weight":"bold",
				"cursor":"pointer"
	});
}

function createGallery(){


 		var windowWidth=$("#gallery_panel").parents("section").width();
	 $("#gallery_panel").parents("section").css('position','relative');
		
		 
		 $("#gallery_panel").carouFredSel({
		   		circular: false,
		    	width: windowWidth,
			    height: "variable",
			    padding: "auto",
			    items: "variable",
			    auto: false,
			    prev: {
			        button: "#gallery-prev",
			        key: "left"
			    },
			    next: {
			        button: "#gallery-next",
			        key: "right"
			    },
			    pagination: true
			});

}

$(window).load(function(){
	$("#facebook-modal").append('<iframe src="http://www.facebook.com/plugins/likebox.php?href=https%3A%2F%2Fwww.facebook.com%2Foutsidein.uk&amp;width=460&amp;colorscheme=light&amp;show_faces=true&amp;border_color&amp;stream=true&amp;header=true&amp;height=427" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:460px; height:427px;" allowTransparency="true"></iframe>');
});


