// Project: Senoda
// File: custom.js (custom jquery functions)
// Creator: VIM Interactive, Inc.
// Copyright: (c) 2011 - VIM Interactive, Inc.

$(function(){
	
	$('#accordion').accordion();
	
	$('#accordion h4:first, #accordion .ui-state-active a:first').css({
		'border-top-left-radius':'7px',
		'border-top-right-radius':'7px',
		'-moz-background-clip':'padding',
		'-webkit-background-clip':'padding-box',
		'background-clip':'padding-box'
	});
	
	$('#accordion h4:last, #accordion .ui-accordion-content:last, .ui-widget').css({
		'border-bottom-left-radius':'7px',
		'border-bottom-right-radius':'7px',
		'-moz-background-clip':'padding',
		'-webkit-background-clip':'padding-box',
		'background-clip':'padding-box'
	});
	
//homepage slider
	
	//case study small image movement
	$('#slider_images img:first').animate({'bottom':'73px'},400, function() {$(this).addClass('active');})
	
	$('#slider_images img').hover(function() {
		if ($(this).hasClass('active')) {
			return false
		}
		$(this).stop().animate({'bottom':'20px'}, 200, function() {
			if(!$(this).hasClass('active')) {
				
				$(this).click(function() {
					
					$('#slider_images img').removeClass('active').stop().animate({'bottom':'0'}, 300, function() {
						//animation complete
					});
					$(this).addClass('active').stop().animate({'bottom':'73px'},400, function(){
						//animation complete
					})
					
				})
				
			}
		});
	},
	function() {
		
		if(!$(this).hasClass('active')) {
		$(this).stop().animate({'bottom':'0'}, 300, function() {
			//animation complete
		});
		}
		
	});
	
//show image and info
	
		var img = $('#slider_images img');
	
		img.click(function () {
			
			var info_img = $(this).attr('id') + '_img';
			var info_info = $(this).attr('id') + '_info';
		
			$('.slider_info_img')
				.css('display','none')
				.filter(info_img).css('display','block');
		
			$('.slider_info')
				.css('display','none')
				.filter(info_info).css('display','block');
			
			
		});
		

	
// for sidebar contact form labels
	$(".portlet_contact label").inFieldLabels();
	
	// enables the datepicker on the request a quote page
	$( "#delivery_date" ).datepicker();
	
	//shows and hides overlay of work samples on the work page
	$('.work_item').hover(function() {
		$(this).find('.work_info').stop(true, true).fadeIn();
	},function() {
		$(this).find('.work_info').stop(true, true).fadeOut();
	});
	
// for lightbox on work page
	
	$('.cb_link').each(function(){
		var div = '#work_slide' + this.id;
		var group = $(this).attr('rel');		
		$(this).colorbox({width:"670px", inline:true, href:div, rel:group});
	});
	
	
	
	
// for thanks messages on forms
	var hash = window.location.hash;
	
	$('#contact_form, #request_form').each(function(){
		if (hash == '#thank-you'){
			$(this).hide().html('<h1>Thank you for your submission</h1>').fadeIn();
		}
	});
	
// for fileshare page
//
//
	//
	$('.files button').click(function(e){
		e.preventDefault()
		//var parent = $(this).parent().find("input[type='file']");
		
		$(this).hide();
		var id = this.id;

		$(id).show().find("input.switch").removeAttr("disabled");

				
	});

	// loads spinner after submit
	$('#contact_form').submit(function(){
		
		$('#overlay').show();
		$(this).find('#submit').attr('disabled','disabled');

		//return false;


	});
	
	// disable empty file inputs to fix freeform
	$('#submit').click(function(e){
	
		$("input.switch").each(function(){
			if (! $(this).attr('disabled')) {
				if (this.value){
				//	console.log(this.value);
				}
				else {
					$(this).attr('disabled', 'disabled');
				}
			}
		});




		
		
	});
	
	
// Request a quote autofill rep field with dropdown value
	$('#request_form #recipient_email').change(function(){
		var sel = "#recipient_email option[value='" + $(this).val() + "']";
		$('#request_form #rep').val($(sel).text());
	});
	
});
