$(document).ready(function(){

	//FAQ slider
		$('div.faq div.fontsup.faq').hide();
		$('div.faq h3').bind('click',function(){$(this).next().toggle();});

	//Show blog comments
		$('#show_comments').bind('click',function(){$('#comments').show();});
		$('#add_comment').bind('click',function(){$('#comments').show();});
		
	// SUB MENU EFFECT 
		$('li.pm').hover(
						function(){$(this).addClass('pmo');},
						function(){$(this).removeClass('pmo');});
	// BOTTOM NAV 
		$('.footer_btn')
				.hover(
						   function(){
						   		var a = $(this);
								var img = a.find('img');
								if(img.attr('src').indexOf('_click') == -1){
									var b = a.attr('id');
									img.attr('src','/images/b2/'+b+'_hover.png');
								}
						   },
						   function(){
						   		var a = $(this);
								var img = a.find('img');
								if(img.attr('src').indexOf('_click') == -1){
									var b = a.attr('id');
									img.attr('src','/images/b2/'+b+'.png');
								}
						   }
					   )
				.bind('click',function(){
									   			// CLOSE ANY OPEN DRAWERS 
													if(selectedFooter != $(this).attr('id')){closeFooter();}
												

													var a = $(this);
													var num = a.metadata().num;
													var img = a.find('img');
													if($('#dpopup'+num).css('display') == 'block'){
														var b = a.attr('id');
														$('#dpopup'+num).hide("slide", { direction: "down" }, 400);
														img.attr('src','/images/b2/'+b+'.png');
														selectedFooter = '';
													}else{
														var b = a.attr('id');
														$('#dpopup'+num).show("slide", { direction: "down" }, 400);
														img.attr('src','/images/b2/'+b+'_click.png');
														selectedFooter = b;
													}
											});
		
		$('.popupClose').bind('click',closeFooter);
		
				//focus quick contacts
					$('input#name').focus(function() {$(this).val('');}); 
					$('input#email').focus(function() {$(this).val('');}); 
					$('input#message').focus(function() {$(this).val('');}); 
				
				//validate quick contact
					$('#quick_contact').validate({
						rules: {
							email: {
								email: true
							}
						},
						messages: {
							name: "", 
							email: {
								required: "",
								email: ""
							},
							message: ""
						}
					});
					
			/* FILE REPLACEMENTS */
			
			(function($) {
			    
			    $.fn.filestyle = function(options) {
			                
			        /* TODO: This should not override CSS. */
			        var settings = {
			            width : 250
			        };
			                
			        if(options) {
			            $.extend(settings, options);
			        };
			                        
			        return this.each(function() {
			            
			            var self = this;
			            var wrapper = $("<div>")
			                            .css({
			                                "cursor":"pointer",
											"width": settings.imagewidth + "px",
			                                "height": settings.imageheight + "px",
			                                "background": "url(" + settings.image + ") 0 0 no-repeat",
			                                "background-position": "right",
			                                "display": "inline",
			                                "position": "absolute",
			                                "overflow": "hidden"
			                            });
			                            
			            var filename = $('<input class="file">')
			                             .addClass($(self).attr("class"))
			                             .css({
			                                 "display": "inline",
			                                 "width": settings.width + "px"
			                             });
			
			            $(self).before(filename);
			            $(self).wrap(wrapper);
			
			            $(self).css({
			                        "position": "relative",
			                        "height": settings.imageheight + "px",
			                        "width": settings.width + "px",
			                        "display": "inline",
			                        "cursor": "pointer",
			                        "opacity": "0.0"
			                    });
			
			            if ($.browser.mozilla) {
			                if (/Win/.test(navigator.platform)) {
			                    $(self).css("margin-left", "-142px");                    
			                } else {
			                    $(self).css("margin-left", "-168px");                    
			                };
			            } else {
			                $(self).css("margin-left", settings.imagewidth - settings.width + "px");                
			            };
			
			            $(self).bind("change", function() {filename.val($(self).val());});
			      
			        });
			    };
			})(jQuery);
			$(function(){
			$(".file").filestyle({ 
			    image: "http://www.brilliant2.com/btn-choose-file.gif",
			    imageheight : 22,
			    imagewidth : 79,
			    width : 125
			});
			});
		
});

/* FUNCTION FOR CLOSING THE FOOTER DRWAERS */

	var selectedFooter = '';
			
	function closeFooter(){
		if(selectedFooter != ''){
			var a = $('#'+selectedFooter);
			var num = a.metadata().num;
			var img = a.find('img');
			$('#dpopup'+num).hide("slide", { direction: "down" }, 400);
			img.attr('src','/images/b2/'+selectedFooter+'.png');
			selectedFooter = '';
		}
	};