// JavaScript Document
(function($){
   $(document).ready(function(){
							  
							  
	function mainmenu(){
	$(" ul#sub-nav ul ").css({display: "none"}); // Opera Fix
	$(" ul#sub-nav li").hover(function(){
			$(this).find('ul:first').css({visibility: "visible",display: "none"}).slideDown(200);
			},function(){
			$(this).find('ul:first').css({visibility: "hidden"});
			});
	}

	mainmenu();
	
	$('.browse .click').change(function(){
			var inputval = $(this).val();
			var file = inputval.replace(/^.*\\/, '');	
			$(this).siblings('.text').val(file);
		});

	
	$('#project-navigation br').remove();
	$('#photogallery a , #newsgallery .news-list a, #project #slide .thumbnails a, .deptlist a').fancybox({
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
		'easingIn'      : 'easeOutBack',
		'easingOut'     : 'easeInBack',
		'centerOnScroll'    : true,
		'hideOnOverlayClick' : false,
		'hideOnContentClick' : false,
		'titleShow' : true
		});
	$('.map, .video').fancybox({
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
		'centerOnScroll'    : true,
		'hideOnOverlayClick' : false,
		'hideOnContentClick' : false
		});
	$('.panorama').fancybox({
		'height' : 480,
		'width' : 860,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
		'centerOnScroll'    : true,
		'hideOnOverlayClick' : false,
		'hideOnContentClick' : false
		});	
		
	var this_ul = $('ul#news_promos li').size();
	if ( this_ul <= 4 ) {
		$('.nav .drop.promos .wrap').addClass('short')
		} 

	$('.contactform fieldset:first-child').show();
	$('.businesstype li:first-child').addClass('active');
	
	$(".businesstype li").click(function(){
	   $(".businesstype li").removeClass('active')
	   $(this).addClass('active')
		})
	$(".businesstype li a").click(function () {
	   $(".contactform fieldset").hide();
	   var content_show = $(this).attr("title");
	   $("#"+content_show).show();
	  	});		
	
	$("#faqs ol li a").click(function () {
	   var content_show = $(this).attr("title");
	   $("#"+content_show).show();
	  	});
	
	$("#project h2 a").click(function () {
	   var content_show = $(this).attr("title");
	   $("#"+content_show).show();
	  	});
	
	//archives-articles
	$('.article-list li:first-child .news-list').show();
	$('.article li:first-child').addClass('active');
	
	$(".article-list li").click(function(){
	   $(".article-list li").removeClass('active')
	   $(this).addClass('active')
		})
	$(".article-list li span a").click(function () {
	   $(".article-list div").hide();
	   var content_show = $(this).attr("title");
	   $("#"+content_show).toggle();
	  	});
	
		//archives-video
	$('.video-list li:first-child .news-list').show();
	$('.video li:first-child').addClass('active');
	
	//$(".video-list li").click(function(){
	//   $(".video-list li").removeClass('active')
	//   $(this).addClass('active')
	//	})
	$(".video-list li span a").unbind('click').bind('click',function (event) {
	   $(".video-list li").removeClass('active');
       $(this).parent().parent().addClass('active');
	   var content_show = $(this).attr("title");
       $("#"+content_show).toggle();
      $(".video-list div:not(#"+content_show+")").hide();
   }
   );
	
		//archives-audio
	$('.audio-list li:first-child .news-list').show();
	$('.audio li:first-child').addClass('active');
	
	//$(".audio-list li").click(function(){
	//   $(".audio-list li").removeClass('active')
	//   $(this).addClass('active')
	//	})
	$(".audio-list li span a").unbind('click').bind('click',function (event) {
      $(".audio-list li").removeClass('active');
       $(this).parent().parent().addClass('active');
	   var content_show = $(this).attr("title");
       $("#"+content_show).toggle();
      $(".audio-list div:not(#"+content_show+")").hide();
	  	});
	
	//gallery-list
	$('.gallery-list li:first-child .news-list').show();
	$('.gallery-list li:first-child').addClass('active');
	
	//$(".gallery-list li").click(function(){
	//   $(".gallery-list li").removeClass('active')
	//   $(this).addClass('active')
	//	})
	$(".gallery-list li span a").click(function () {
	   $(".gallery-list li").removeClass('active');
       $(this).parent().parent().addClass('active');
	   var content_show = $(this).attr("title");
	   $("#"+content_show).toggle();
       $(".gallery-list div:not(#"+content_show+")").hide();
	  	});
	
	//thumbnail buttons
	var numCount = $('.thumbnails ul li').length;
  	var innerBox = $('.thumbnails ul');
  	innerBox.css({'width' : numCount * 99 });
  
  $('#buttons a.next').click(function(){
   var curScroll = $('.thumbnails').scrollLeft();
   $('.thumbnails').animate({scrollLeft: curScroll + 295}, 1000);
  })
  
  $('#buttons a.prev').click(function(){
   var curScroll = $('.thumbnails').scrollLeft();
   $('.thumbnails').animate({scrollLeft: curScroll - 295}, 1000);
  })
	
	
	Cufon.set('fontFamily', 'AnzianoSmallCaps').replace('#left-home-content ul li a', {hover:{color: '#519a25'}});
	Cufon.set('fontFamily', 'HelveticaNeue LT 57 Cn').replace(
		'#about h1, #about h2, #news h1, #news h2, #faqs h1, #job h1, #job h2, #seller h1, #seller h2, #sidemenu ul li a, .sidebar h5, #house h3, .sidebar h3, #project h1, #project h2,  #project h3,  .sidebar h4, #contact h1, ul.house-view li h2, #faqs ol li a, #contact h4, #about .caption');

	});
})(jQuery);
/* Contact Forms */

function setOptions(chosen) {
	var dropdownsales = document.formsales.dropdownsub;
	 
	dropdownsales.options.length = 0;
		if (chosen == "sales") {
		  dropdownsales.options[dropdownsales.options.length] = new Option('Please select one of the options above first','sales');
		  $('#dropdownsub').show();
		  $('#modelhouse').show();
		  $('#others').hide();
		  $('#others_lbl').hide();	
		  $('#space1').hide();
		}
		if (chosen == "Pacific Terraces Community") {
		  $('#dropdownsub').show();
		  $('#others').hide();
		  $('#others_lbl').hide();
		  $('#modelhouse').show();
		  $('#space1').hide();
		  dropdownsales.options[dropdownsales.options.length] = new Option('Cedar','cedar');
		  dropdownsales.options[dropdownsales.options.length] = new Option('Juniper','juniper');
		  dropdownsales.options[dropdownsales.options.length] = new Option('Chestnut','chestnut');
		  dropdownsales.options[dropdownsales.options.length] = new Option('Linden','linden');
		  dropdownsales.options[dropdownsales.options.length] = new Option('Hazel','hazel');
		}
		
		if (chosen == "Pacific Terraces Community South") {
		  $('#dropdownsub').show();
		  $('#others').hide();
		  $('#others_lbl').hide();
		  $('#modelhouse').show();
		  $('#space1').hide();
		  dropdownsales.options[dropdownsales.options.length] = new Option('Sycamore','sycamore');
		  dropdownsales.options[dropdownsales.options.length] = new Option('Cherry','cherry');
		  dropdownsales.options[dropdownsales.options.length] = new Option('Aspen','aspen');  
		}
		if (chosen == "Mahogany Place Lipa") {
		  $('#dropdownsub').show();
		  $('#others').hide();
		  $('#others_lbl').hide();
		  $('#modelhouse').show();
		  $('#space1').hide();;
		  dropdownsales.options[dropdownsales.options.length] = new Option('Cedar','cedar');
		  dropdownsales.options[dropdownsales.options.length] = new Option('Juniper','juniper');
		  dropdownsales.options[dropdownsales.options.length] = new Option('Chestnut','chestnut');
		  dropdownsales.options[dropdownsales.options.length] = new Option('Linden','linden');
		  dropdownsales.options[dropdownsales.options.length] = new Option('Rosewood','rosewood');
		}
		if (chosen == "Pacific Renaissance Villas") {
		  $('#dropdownsub').show();
		  $('#others').hide();
		  $('#others_lbl').hide();
		  $('#modelhouse').show();
		  $('#space1').hide();
		  dropdownsales.options[dropdownsales.options.length] = new Option('Chestnut','chestnut');
		  dropdownsales.options[dropdownsales.options.length] = new Option('Linden','linden');
		}
		
		if (chosen == "Pacific Woods West") {
		  $('#dropdownsub').show();
		  $('#others').hide();
		  $('#others_lbl').hide();
		  $('#modelhouse').show();
		  $('#space1').hide();
		  dropdownsales.options[dropdownsales.options.length] = new Option('Jasmine','jasmine');
		  dropdownsales.options[dropdownsales.options.length] = new Option('Sunflower','sunflower');
		}
		if (chosen == "Richmond Park Townhomes") {
		  $('#dropdownsub').show();
		  $('#others').hide();
		  $('#others_lbl').hide();
		  $('#modelhouse').show();
		  $('#space1').hide();
		  dropdownsales.options[dropdownsales.options.length] = new Option('Regina','regina');
		  dropdownsales.options[dropdownsales.options.length] = new Option('Sophia','sophia');
		}
		if (chosen == "Others") {
		  $('#dropdownsub').hide();
		  $('#modelhouse').hide();
		  $('#others').show();
		  $('#others_lbl').show();
		  $('#space1').show();
		 }
}
function setOptionsAgent(chosen) {
		var dropdownagent = document.formsales.dropdownagent;
	 
	dropdownagent.options.length = 0;
		if (chosen == "No") {
		dropdownagent.options[dropdownagent.options.length] = new Option('No','No');
		dropdownagent.options[dropdownagent.options.length] = new Option('Yes','Yes');	
			$('#agentname_lbl').hide();
		 	$('#agent_name').hide();
			$('#space2').hide();
		    $('#space3').hide();
		}
		if (chosen == "Yes") {
		  //$('#dropdownagent').show();
		  dropdownagent.options[dropdownagent.options.length] = new Option('Yes','Yes');
		  dropdownagent.options[dropdownagent.options.length] = new Option('No','No');
		  $('#agentname_lbl').show();
		  $('#agent_name').show();
		  $('#space2').show();
		  $('#space3').show();
		}
}

function setOptionsBusinessType(chosen) {
		var dropdownbusinesstype = document.formbusinesstype.dropdownbusinesstype;
	 
		dropdownbusinesstype.options.length = 5;
		if (chosen == "Please Select Here") {
			$('#sales-related').hide();
			$('#csr').hide();
			$('#hr-related').hide();
			$('#other').hide();
		}		
		if (chosen == "Sales Related") {
			$('#contactform').show();
			$('#sales-related').show();
			$('#csr').hide();
			$('#hr-related').hide();
			$('#other').hide();
		}
		if (chosen == "Customer Service Related") {
			$('#contactform').show();
			$('#csr').show();
			$('#sales-related').hide();	
			$('#hr-related').hide();
			$('#other').hide();
		}
		if (chosen == "HR Related") {
			$('#contactform').show();
			$('#hr-related').show();
			$('#sales-related').hide();	
			$('#csr').hide();
			$('#other').hide();
		}
		if (chosen == "Others") {
			$('#contactform').show();
			$('#other').show();
			$('#sales-related').hide();	
			$('#csr').hide();
			$('#hr-related').hide();			
		}
}

       function setYears(inst){
            var str = '';
            str +='<option selected="selected" value="">Select one</option>';
            if(inst=='1'){
                str+='<option value="5">5 years</option>';
                str+='<option value="10">10 years</option>';
                str+='<option value="15">15 years</option>';
                str+='<option value="20">20 years</option>';
                str+='<option value="25">25 years</option>';
                str+='<option value="30">30 years</option>';
            }
            if(inst=='2' || inst=='3'){
                str+='<option value="10">10 years</option>';
                str+='<option value="15">15 years</option>';
                str+='<option value="20">20 years</option>';
            }
            if(inst=='4'){
                str+='<option value="3">3 years</option>';
                str+='<option value="5">5 years</option>';
                str+='<option value="10">10 years</option>';
            }
            $('#years').html(str);
        }
		
        function computeMe(){
            var a = $('#loanamount').val();
            var f = $('#financial').val();
            var y = $('#years').val();
            a=jQuery.trim(a);
            f=jQuery.trim(f);
            y=jQuery.trim(y);
            if(isNaN(a)){
                alert('Please enter a valid amount');
                return false
            }
            if(f=='' || y=='' || a==''){
                alert('Please complete all fields');
                return false
            }
            $.ajax({
                type: "POST",
                url: "./index.php/frontend/projects/loancompute",
                data: $('#frm').serialize(),
                success: function(data){
                    $('#amortization').html(data);
                }
            });
        }
