$(document).ready(function(){
	//DEBUG = true;
	////$.log("debug active");
	//init local nav links
	//remove list bullets
	// $("#blq-local-nav").css("list-style","none");
	 //$("#blq-local-nav ul").css("list-style","none");
	//add corners
	$("#site-link").corner("#05050C 4px");
	$("#content-links").corner("#05050C 4px"); 
	//nav rollover
	$("#blq-local-nav li a").hover(
		function () {
			 $(this).parent().css("background-color","#0E0F0A");
		}, 
		function () {
			$(this).parent().css("background-color","#212121");
		}
	);
	
	
	
	//comment message alternating background
	$('.#sxswComments .commentMessages p:even').css("background-color","#2C2C2C");
	
	//padding for promo - audio and video
	$('#audioVideoPromo dl:even').css("padding-right","14px");
	$('#photosPromo dl:even').css("padding-right","14px");
	
	//init comments form 
	 //$.log('init comments form'); 
		var options = { 
			beforeSubmit:  validate,  // pre-submit callback 
			success:       showResponse,  // post-submit callback 
			error: 		 showResponse
		}; 
		// bind form using 'ajaxForm' 
		$('#commentsForm').ajaxForm(options); 
		//add feedback form
		$('#commentsForm').prepend("<div></div>");
		$('#commentsForm div:first').toggle();
		$('#commentsForm div:first').attr("id","cFeedback");
		
		
		
	
	
	// pre-submit callback 
	function validate(formData, jqForm, options) { 
	

	for (var i=0; i < formData.length; i++) { 
			 
			
			 var nameStatus;
			 var commentStatus;
			 var feedback;
			if (!formData[i].value) { 
				
				//add borders
				if (!formData[2].value){
					$("#commentsName").addClass("emptyField");
					 nameStatus = false;
					}else{
					$("#commentsName[class='emptyField']").removeClass("emptyField");
					var nameStatus = true;
					};
				if (!formData[3].value){
					$("#commentsInput").addClass("emptyField");
					commentStatus = false;
					}else{
					$("#commentsInput[class='emptyField']").removeClass("emptyField");
					commentStatus = true;
					};
						
				//add message
				
				//$("#cFeedback").toggle();
				 //$.log('nameStatus = '+nameStatus); 
				 //$.log('commentStatus = '+commentStatus); 
				if (!nameStatus && !commentStatus){
					feedback = "<p>Please enter your name and a message.</p>"
				}else if (!nameStatus && commentStatus){	
					feedback = "<p>Please enter your name.</p>"
				
				}else if (nameStatus && !commentStatus){	
					feedback = "<p>Please enter a message.</p>"
				
				}
				$("#cFeedback").show().html(feedback);
				$("div#cFeedback").corner(); 
				return false; 
			} 
		} 
    ////$.log('Both fields contain values.'); 
	//fade out form
	jqForm.fadeOut(500);
	//jqForm.siblings().fadeOut(500);
	//add feedback
	$(".commentForm h3").html("Sending comment...");
	
	};
 
	// post-submit callback 
	function showResponse(responseText, statusText)  { 
		////$.log('status: ' + statusText); 
		if(statusText == "success"){
		$(".commentForm h3").html('Thanks for your comment.');
		$(".commentForm h3").after("<p>It will be posted here following moderation.</p>")						  
		//<br><p class="caption">Disclaimer: The BBC may edit your comments and cannot guarantee that all e-mails will be published. </p>
		
		}else{
			$(".commentForm h3").html("Sorry an error has occurred your message may not have been sent.");
			
			};
	}; 
	
	
	//lightbox-enabled
	//get all links with lightbox-enabled and change the urls to be the image you want to view
	
	$(".lightbox-enabled").bind("click", function(e){
		e.preventDefault();								 
  		
		var thisHref = $(this).attr("href");
	   
	   //$.log('fullHref: ' + fullHref);
	   //get query string
		qsCheck = thisHref.indexOf("?");
		if (qsCheck >=0){
			qs = thisHref.split("?")[1];
			//split into value pairs
			//$.log('qs: ' + qs);
			var valuePairs = qs.split("&");
			//$.log('valuePairs: ' + valuePairs);
			
			var lightboxPath="";
			$.each(valuePairs, function(n){
				t = valuePairs[n].split("=");
				var name = t[0];
				//$.log('name: ' + name);
				var value = t[1];
				if(name == "lightboxPath"){
						lightboxPath = value;
					}
			});	
			
		}else{
			t = thisHref.split("=");
			var name = t[0];
			//$.log('name: ' + name);
			var value = t[1];
			if(name == "lightboxPath"){
					lightboxPath = value;
				}	
			
		}
		
		
		
	 	$(this).attr("href",lightboxPath);
		$(this).lightbox({start:true,events:false});
		
		});
	
	
	
		
		
      
	
	
});	