/*------------------------------------------------------------
 Author: Femy Praseeth
-------------------------------------------------------------- */ 

$(function () {

	/*------------------------------------------------------------
	 Home Page tabs and secondary navigation 
	-------------------------------------------------------------- */
	var panels = $("#panelWrap article"),
    tabs = $("#bdyHome #tabs li a");
	panels.hide();
	tabs.click(function(e){
   		e.preventDefault();
   		panels.hide();
	   	panelheight = $(this.hash).outerHeight();
	   	$(this.hash).show().parent().animate({"height":  panelheight});
		tabs.removeClass("selected");
	   	$(this).addClass("selected");
	}).filter(':first').click();
	
	$("#tabs li a").click(function(e){
   		$("#tabs li a").removeClass("selected");
	   	$(this).addClass("selected");
	});
	

	/*------------------------------------------------------------
	 Animation for Back to Top arrow 
	-------------------------------------------------------------- */
	$("#back-top").hide();
	$(window).scroll(function () {
		if ($(this).scrollTop() > 100) {
			$('#back-top').fadeIn();
		} else {
			$('#back-top').fadeOut();
		}
	});
	// scroll body to 0px on click
	$('#back-top a').click(function () {
		$('body,html').animate({
			scrollTop: 0
		}, 800);
		return false;
	});

	/*------------------------------------------------------------
	 Filtering the portfolio section based on the sub categories
	-------------------------------------------------------------- */
	$('ul#filter li a').click(function() {
		$(this).css('outline','none');
		$('ul#filter .current').removeClass('current');
		$(this).parent().addClass('current');
	
		var filterVal = $(this).text().toLowerCase().replace(' ','-');
	
		if(filterVal == 'all') {
			$('ul#portfolio li.hidden').fadeIn('slow').removeClass('hidden');
		} 
		else {
			$('ul#portfolio li').each(function() {
				 if(!$(this).hasClass(filterVal)) {
				 $(this).fadeOut('normal').addClass('hidden');
				 } else {
				 $(this).fadeIn('slow').removeClass('hidden');
				 }
			});
		}
		return false;
	});
 
	/*------------------------------------------------------------
	 Accordion in the news section
	-------------------------------------------------------------- */
	$( "#accordion" ).accordion({
			autoHeight: false,
			navigation: true
	});
 
 	/*------------------------------------------------------------
	 Colorbox
	-------------------------------------------------------------- */
  	$("a[rel='eden']").colorbox({transition:"fade"});
	$("a[rel='efi-dp']").colorbox({transition:"fade"});
	$("a[rel='efi-f-prod']").colorbox({transition:"fade"});
	$("a[rel='doubletree']").colorbox({transition:"fade"});
	$("a[rel='quova']").colorbox({transition:"fade"});
	$("a[rel='solutionset']").colorbox({transition:"fade"});
	$("a[rel='rsa']").colorbox({transition:"fade"});
	$("a[rel='om']").colorbox({transition:"fade"});
	$("a[rel='fiery-n']").colorbox({transition:"fade"});
	$("a[rel='efisp']").colorbox({transition:"fade"});
	$("a[rel='flavors']").colorbox({transition:"fade"});
	$("a[rel='kp']").colorbox({transition:"fade"});
	//Example of preserving a JavaScript event for inline calls.
	$("#click").click(function(){ 
		$('#click').css({"background-color":"#f00", "color":"#fff", "cursor":"inherit"}).text("Open this window again and this message will still be here.");
		return false;
	});
 
	 /*------------------------------------------------------------
	 Contact Us 
	 -------------------------------------------------------------- */
	  $('.error').hide();
	  $('input.text-input').focus(function(){
		$(this).css({backgroundColor:"#000000"});
	  });
	  $('input.text-input').blur(function(){
		$(this).css({backgroundColor:"#1f1f1f"});
	  });
	  $(".button").click(function() {
	  // validate and process form
	  // first hide any error messages
	  $('.error').hide();
	  var name = $("input#name").val();
	  if (name == "") {
		$("label#name_error").show();
		$("input#name").focus();
		return false;
	  }
	  var email = $("input#email").val();
	  if (email == "") {
		  $("label#email_error").show();
		  $("input#email").focus();
		  return false;
	  }
	  var phone = $("input#phone").val();
	  /*if (phone == "") {
		  $("label#phone_error").show();
		  $("input#phone").focus();
		  return false;
	  }*/
	  var tmessage = $("textarea#tmessage").val();
	  var dataString = 'name='+ name + '&email=' + email + '&phone=' + phone + '&tmessage=' + tmessage;
	  //alert (dataString);return false;
	  $.ajax({
		  type: "POST",
		  url: "/bin/process.php",
		  data: dataString,
		  success: function() {
			$('.colMain').html("<div id='message'></div>");
			$('#message').html("<h6>thank you for contacting <span>femKreations!</span></h6>")
				.append("<p>You just made our day! We will get back to you when we take a break from designing and developing. Usually all enquiries will be responded to within 48 hours, unless it is a weekend, in which case we wll be in touch with you first thing on Monday morning!</p><p>In the meanwhile, admire some of the work we have included in our portfolio. </p><p>&ndash;Femy Praseeth</p>")
				.hide()
				.fadeIn(1500); // end fadeIn function
			} //end message html chaining
		  }); // end success function
		  return false;
	  }); // end ajax
		
 	
});



