//notify
$base_url = "http://nccc.com.ph/";
//$base_url = "http://10.33.43.4/nccc/";

function display_input_error(notifyid, message, color){
	if(color == "blue"){
		$("#"+notifyid).removeClass("red");
		$("#"+notifyid).addClass("blue");
	}
	else{
		$("#"+notifyid).removeClass("blue");
		$("#"+notifyid).addClass("red");
	}
	
	$("#"+notifyid).text(message);
	$("#"+notifyid).fadeIn();
}

function hide_input_error(notifyid){
	$("#"+notifyid).fadeOut();
}

//checking of input
function checklength(id, minlength, maxlength, notifyid, fieldname){
	if(($("[name="+id+"]").val().length < minlength) || ($("[name="+id+"]").val().length > maxlength)){
		display_input_error(notifyid, fieldname+" must be between "+minlength+" and "+maxlength, "red");
		return false;
	}
	else
		return true;
}

function checkRegexp(id,regexp,notifyid) {
	if ( !( regexp.test( $("[name="+id+"]").val() ) ) ) {
		display_input_error(notifyid, "Invalid email address", "red");
		return false;
	} else 
		return true;
}


//sliding box
$(function (){
	$(".content-slider .pointer").live("click",function(){
			if($(this).parent().children("div").is(":visible")){
				$(this).parent().removeClass("arrow-down");
				$(this).parent().addClass("arrow-up");
				$(this).parent().children("div").slideUp();
			}
			else{
				$(this).parent().removeClass("arrow-up");
				$(this).parent().addClass("arrow-down");
				$(this).parent().children("div").slideDown();
			}
	})
})

//submit news subscription
$(function (){
	$("[name=submitsubscription]").click(function(){
		field_valid = true;
		field_valid = field_valid && checklength("email", 6, 160, "emailsubscription_msg", "Name");
		field_valid = field_valid && checkRegexp("email", /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i,"emailsubscription_msg");
		
		if(!field_valid)
			return false;
		
		display_input_error("emailsubscription_msg", "Sending...", "blue");
		$.post($base_url+"processor",{
			axn 	: "subscribe",
			email 	: $("[name=email]").val()
		},function(data){
			if(data != "1")
				display_input_error("emailsubscription_msg", "You are now subscribe to NCCC", "blue");
			else
				display_input_error("emailsubscription_msg", "Email already exist", "red");
				
			$("[name=email]").val("");
		})
	})
})

//inputtextbox
$(function (){
	$(".inputtextbox").focus(function(){
			$(this).val("");
	})
})

//submitcomment

$(function (){
	$("[name=submitcomment]").click(function(){
		field_valid = true;
		field_valid = field_valid && checklength("com_name", 1, 160, "comment_msg", "Name");
		field_valid = field_valid && checklength("com_email", 6, 160, "comment_msg", "Email");
		field_valid = field_valid && checkRegexp("com_email", /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i,"comment_msg");
		field_valid = field_valid && checklength("com_message", 1, 2000, "comment_msg", "Message");
		
		if(!field_valid)
			return false;
		
		display_input_error("comment_msg", "Sending...", "blue");
		
		$.post($base_url+"processor",{
			axn 	: "addcomment",
			name 	: $("[name=com_name]").val(),
			email 	: $("[name=com_email]").val(),
			msg 	: $("[name=com_message]").val()
		},function(data){
			if(data != "1")
				display_input_error("comment_msg", "Your message has been sent. Thank you for your time.", "blue");
			else
				display_input_error("comment_msg", "Your message was not sent, please retry.", "red");
			
			$("[name=com_name]").val("");
			$("[name=com_email]").val("");
			$("[name=com_message]").val("");
		})
	})
})

/*$(function()
{
	$('.scroll-pane').jScrollPane();
});*/

$(function()
{
	$('a[rel*=facebox]').bind("click", function(){
											
		$id = $(this).attr("id");
		$("div.movie-info-img").html("<img src=\""+$base_url+"_addons/img/uploads/cinema/PRIM-"+$("#img"+$id).val()+"\"/>");
		$("div.movie-info-detail").html("Title: "+$("#title"+$id).val()+"<br/>"+
										"Cast: "+$("#cast"+$id).val()+"<br/><br/>"+
										"Synopsis: "+"<div class=\"movie-info-desc\">"+$("#content"+$id).text()+"</div><br/>"+
										"Director: "+$("#director"+$id).val()+"<br/>"+
										"Producer: "+$("#producer"+$id).val()+"<br/>"+
										"Website: <a href=\""+$("#website"+$id).val()+"\">"+$("#website"+$id).val()+"</a>");	
		
		$("div#facebox table div.content div.myfacebox").removeClass('hidden');
	});
	
	$('a[rel*=facebox]').facebox();
});

$(window).load(function() {
    $('#slider-nivo').nivoSlider({
        effect:'fade', // Specify sets like: 'fold,fade,sliceDown'
        slices:15, // For slice animations
        boxCols: 8, // For box animations
        boxRows: 4, // For box animations
        animSpeed:500, // Slide transition speed
        pauseTime:3000, // How long each slide will show
        startSlide:0, // Set starting Slide (0 index)
        directionNav:true, // Next & Prev navigation
        directionNavHide:true, // Only show on hover
        controlNav:true, // 1,2,3... navigation
        controlNavThumbs:false, // Use thumbnails for Control Nav
        controlNavThumbsFromRel:false, // Use image rel for thumbs
        controlNavThumbsSearch: '.jpg', // Replace this with...
        controlNavThumbsReplace: '_thumb.jpg', // ...this in thumb Image src
        keyboardNav:true, // Use left & right arrows
        pauseOnHover:true, // Stop animation while hovering
        manualAdvance:false, // Force manual transitions
        captionOpacity:0.8, // Universal caption opacity
        prevText: '', // Prev directionNav text
        nextText: '', // Next directionNav text
        beforeChange: function(){}, // Triggers before a slide transition
        afterChange: function(){}, // Triggers after a slide transition
        slideshowEnd: function(){}, // Triggers after all slides have been shown
        lastSlide: function(){}, // Triggers when last slide is shown
        afterLoad: function(){} // Triggers when slider has loaded
    });
});
