$(document).ready(function(){
	initSlideBox();
	initFocus();
	initHover();	
	initSlider();        
        if($('.slideshow .slide-banners img').length > 1){
            initHoverSlide();
        }	
	initDrop();
	initInput();
        initStarRatings();
        initValidate();	
});
function initCufon() {
	Cufon.replace('#main .box-home h3,.title h2, #items h3,.submit-review h4, #top-content .top-list a, #sidebar h4, #bottom-block .contact,.address span a,#sidebar .chat a,#sidebar form input.submit', { fontFamily: 'Arial',hover:true,textShadow: '1px 1px 0 #000000'});
	Cufon.replace('#items span.more a,#sidebar span.more a,.practice a,.drop-list button,#middle-block span.more a,.submit-review input.submit', { fontFamily: 'arial-n',hover:true,textShadow: '1px 1px 0 #fff'});
	Cufon.replace('.follow span', { fontFamily: 'Arial',hover:true,textShadow: '1px 1px 0 #ccc'});
	Cufon.replace('#menu', { fontFamily: 'Arial',textShadow: '1px 1px 0 #000000'});
	Cufon.replace('#menu ul li.active', { fontFamily: 'Arial',hover:true,textShadow: '0 0 1px #B8D2E5'});
}
function initInput(){
	$('input.submit').hover(
	function(){$(this).addClass('ie-hover');},
	function(){$(this).removeClass('ie-hover');}
	);
	$('.top-list a').hover(
	function(){$(this).addClass('ie-hover');},
	function(){$(this).removeClass('ie-hover');}
	);
};
function initHover(){
		$('#menu ul li:not(.active)').hover(function(){
			$(this).addClass('hover');
		}, function(){
			$(this).removeClass('hover');
		});
};
function initSlideBox(){
	$('.slide-area').cycle({ 
		fx:     'fade', 
		speed: '0',
		pager:   '.slide-box .pager',
		timeout: 3000
	});
}
function initFocus(){
	$(".text").each(function(){
		var _val = $(this).val();
		$(this).focus(function(){
			$(this).addClass('focus');
			if ($(this).val() == _val) {
				$(this).val('');
			}
		});
		$(this).blur(function(){
			$(this).removeClass('focus');
			if ($(this).val() == '') {
				$(this).val(_val);
			}
		});
	});
}
function initSlider(){
	$('.slideshow .slide-banners').cycle({ 
		fx:      'fade', 
		speed:  2000, 
		sync:          1,
		next:   '#next2', 
		prev:   '#prev2',
		timeout: 6000
	});        
}
function initHoverSlide() {
	$(".slideshow").hover(
	function(){$("#prev2").css("display","block"),$("#next2").css("display","block");},
	function(){$("#prev2").css("display","none"),$("#next2").css("display","none");}
	)
}
function initDrop(){
	jQuery.each(['backgroundColor', 'borderBottomColor', 'borderLeftColor', 'borderRightColor', 'borderTopColor', 'color', 'outlineColor'], function(i,attr){
		jQuery.fx.step[attr] = function(fx){
			if ( fx.state == 0 ) {
				fx.start = getColor( fx.elem, attr );
				fx.end = getRGB( fx.end );
			}

			fx.elem.style[attr] = "rgb(" + [
				Math.max(Math.min( parseInt((fx.pos * (fx.end[0] - fx.start[0])) + fx.start[0]), 255), 0),
				Math.max(Math.min( parseInt((fx.pos * (fx.end[1] - fx.start[1])) + fx.start[1]), 255), 0),
				Math.max(Math.min( parseInt((fx.pos * (fx.end[2] - fx.start[2])) + fx.start[2]), 255), 0)
			].join(",") + ")";
		}
	});
	function getRGB(color) {
		var result;
		if ( color && color.constructor == Array && color.length == 3 )
			return color;
		if (result = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(color))
			return [parseInt(result[1]), parseInt(result[2]), parseInt(result[3])];
		if (result = /rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(color))
			return [parseFloat(result[1])*2.55, parseFloat(result[2])*2.55, parseFloat(result[3])*2.55];
		if (result = /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(color))
			return [parseInt(result[1],16), parseInt(result[2],16), parseInt(result[3],16)];
		if (result = /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(color))
			return [parseInt(result[1]+result[1],16), parseInt(result[2]+result[2],16), parseInt(result[3]+result[3],16)];
		return colors[jQuery.trim(color).toLowerCase()];
	}
	function getColor(elem, attr) {
		var color;
		do {
			color = jQuery.curCSS(elem, attr);
			if ( color != '' && color != 'transparent' || jQuery.nodeName(elem, "body") )
				break; 
			attr = "backgroundColor";
		} while ( elem = elem.parentNode );
		return getRGB(color);
	};
        height = $('.page-content .drop-list div.text').each(function(){                		              
                $(this).css('height',$(this).height());        
		$(this).hide();
	})
	$('.page-content .drop-list li:not(.close)').live('click',function(){
		$(this).find('div.text').slideDown();
		$(this).find('button').addClass('close').text('CLOSE');
		$(this).addClass('close');
		$(this).find('span').animate({color:"#006ab4"}, 1000 );
		});
	$('.page-content .drop-list li button.close').live('click',function(){
		if($(this).parent().find('div.text').css('display') == 'block'){
			$(this).parent().find('div.text').slideUp();
			$(this).removeClass('close').text('ANSWER');
			$(this).parent().removeClass('close');
			$(this).parent().find('span').animate({color:"#666"}, 1000 );
		}
	});
	$('.page-content .drop-list li:not(.close)').hover(
	function(){$(this).addClass('hover');}, 
	function(){$(this).removeClass('hover');})
}
function initStarRatings() {	
    
    $(".stars").children().not(":radio").hide();
    $(".stars").stars({
        cancelShow: false,
        disableValue: false,
        disabled: false
    });
}
function initValidate() {
    $('#freeform, form.review').submit(function(){
        if($('#name').val() == 'First & Last Name') {
            $('#name').val('');
        }
        if($('#phone_number').val() == 'Phone Number') {
            $('#phone_number').val('');
        }
        if($('#message').val() == 'Tell us About your Case') {
            $('#message').val('');
        }
        if($('#captcha').val() != '8') {
            $('#captcha').val('');
        }
        if($('#full_name').val() == 'First & Last Name') {
            $('#full_name').val('');
        }
        if($('#review').val() == 'Please type your Message here') {
            $('#review').val('');
        }
        if($('#client_location').val() == 'Location') {
            $('#client_location').val('');
        }
    });
    $('#get-help-form, #download-book-form').submit(function(){
        if($('#captcha').val() != '8') {
            $('#captcha').val('');
        }
    });
    $('#freeform, form.review').validate();
    $('#get-help-form').validate();
    $('#download-book-form').validate();
}
