
$(document).ready(function(){
	
	fInk.init();
	$('.executable[rel]').each(function(){
		var $this = $(this);
		var rel = $this.attr('rel');
		try {
			fInk[rel].init($this);
		}
		catch(err){}
		
	});	
	
});
$(document).load(function(){
	
})

var fInk = {
	init: function(){
		this.initialParentWidth = $('#pageContainer').width();
		$('body').addClass(this.browserClass);
		this.searchFocus();
		
	},
	buttonHover: function(){
		$('button').hover(function(){$(this).addClass('hover')},function(){$(this).removeClass('hover')});
	},
	browserClass: function(){
		var $browser = $.browser;		
		if($browser.mozilla){
			if($browser.version < 1.8){
				return "ff1";
			}
			else if($browser.version > 1.8 ){
				return "ff2";
			}
			else {
				return "ff3";				
			}			
		}
		else if($browser.webkit){
			return 'webkit';
		}
		else if($browser.opera){
			return 'opera';
		}		
	},
	searchFocus: function(){
		
		var $texts = $('input[type=text][title], textarea[title]');
    
	    $texts.each(function(){
	        var $this = $(this);
	        if($this.val() == "" || $this.val() == $this.attr('title')){
	            $this.val($this.attr('title')).addClass('default');
	        }       
	    });
	    
	    $texts.focus(function(){
	         var $this = $(this);
	          $this.val(($this.val()===$this.attr('title'))?'':$this.val()).removeClass('default');
	        }).blur(function(){
	            var $this = $(this);
	            $this.val(($this.val()==='')?$this.attr('title'):$this.val()).addClass(($this.val()===$this.attr('title'))?'default':'');
	        });	     
			
			
		}
}

/* 
 * Javascript object to represent Drop downs
 * 
 */
fInk.dropDownNavs = {
	init: function(el){
		var config = {    		
		         sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    		
		         //interval: 50,  // number = milliseconds for onMouseOver polling interval    		
		         over: doOpen,   // function = onMouseOver callback (REQUIRED)    		
		         timeout: 10,   // number = milliseconds delay before onMouseOut    		
		         out: doClose    // function = onMouseOut callback (REQUIRED)    		
		    };

    function doOpen() {
        $(this).addClass("expanded");
        $('ul:first',this).css('visibility', 'visible');
    }

    function doClose() {
        $(this).removeClass("expanded");
        $('ul:first',this).css('visibility', 'hidden');
    }

    $("ul.down li").hoverIntent(config);
    $("ul.down li ul li:has(ul)").find("a:first").append(" &raquo; ");
		}
	
}

/* 
 * Javascript object to represent lighbox
 * 
 */
fInk.lightBox = {
	init: function(el){
		if ($('body').hasClass('ie6')) {
			$('div.nyroModalCont').bgiframe();
		}
		$(function() {
		  $('.nyroModal').nyroModal();
		});
		}
}


/* 
 * accordion object
 * 
 */
fInk.accordBox = {
	init: function(el){
		$('.faq-block > li:first-child div').css('display' , 'block');
	$('.faq-block > li:first-child a').addClass('down');
	$("a[name^='faq-']").each(function() {
		$(this).click(function() {
			if( $("#" + this.name).is(':hidden') ) {
				$(this).addClass('down');
				$("#" + this.name).fadeIn('slow');
			} else {
				$(this).removeClass('down');
				$("#" + this.name).fadeOut('slow');
			}			
			return false;
		});
	});
	}
}
/* 
 * accordion object need help
 * 
 */
fInk.accordBoxHelp = {
	init: function(el){
		$('.help-block > li:first-child div').css('display' , 'block');
	$('.help-block > li:first-child a').addClass('down');
	$("a[name^='help-']").each(function() {
		$(this).click(function() {
			if( $("#" + this.name).is(':hidden') ) {
				$(this).addClass('down');
				$("#" + this.name).fadeIn('slow');
			} else {
				$(this).removeClass('down');
				$("#" + this.name).fadeOut('slow');
			}			
			return false;
		});
	});
	}
}


/* 
 * change Header style
 * 
 */

fInk.changeHeaderFonts = {
	init: function(el){
		//$('#imageH').change(function(){
         //   $('#imagePreviewH').html('<img src="'+$('#imageH').val()+'"/>');
   		// });
		
		$("#imageH").change(function() {
	     $("#imagePreviewH").empty();
	     if ( $("#imageH").val()!="" ){
	        $("#imagePreviewH").append("<img src=\"" + $("#imageH").val()  + "\" />");
	     }
	     else{
	        $("#imagePreviewH").append("displays image here");
	     }
	   });
	}
}

/* 
 * change Body style
 * 
 */

fInk.changeBodyFonts = {
	init: function(el){
		
		$("#imageB").change(function() {
	     $("#imagePreviewB").empty();
	     if ( $("#imageB").val()!="" ){
	        $("#imagePreviewB").append("<img src=\"" + $("#imageB").val()  + "\" />");
	     }
	     else{
	        $("#imagePreviewB").append("displays image here");
	     }
	   });
	}
}

/* 
 * 
 * Show and hide content News Landing Page
 * 
 */

fInk.popupLayers = {
	init: function(el){
		// Customer service order page
		$('div.popup1').hide();
		$('div.popup2').hide();
	  
		$('a.popupContainer1').bind('click',function(){
			$(this).addClass('expanded').next().slideDown('fast')	
			.parent()
			.addClass('expanded');
	
			$(this).parent().hover(function(){},function(){
				$(this).removeClass('expanded').parents().find('div.popup1').hide().removeClass('expanded').next().slideUp('fast'); //When the mouse hovers out of the subnav, move it back up
				
			});
			return false;
		});	
		$('a.popupContainer2').click(function(){
			$(this).addClass('expanded').next().slideDown('fast')	
			.parent()
			.addClass('expanded');
			
			$(this).parent().hover(function(){},function(){
				$(this).removeClass('expanded').parents().find('div.popup2').hide().removeClass('expanded').next().slideUp('fast'); //When the mouse hovers out of the subnav, move it back up
				
			});
			return false;
		});
		
		$('a.popupContainer1').hover( function(){  $(this).addClass('hovered'); }, function(){ $(this).removeClass('hovered');  });
		
	}
	
}


/* 
 * 
 * rotating image
 * 
 */

fInk.rotateImage = {
	init: function(el){
		// Initialize Minimal Galleriffic Gallery "#controls div.ss-controls a"
				$('#thumbs').galleriffic({
					imageContainerSel:      '#slideshow',
					controlsContainerSel:   '#controls',
					captionContainerSel:       '#caption',
					 delay:                 8000, // in milliseconds
					autoStart:              true
				});
				
	}
	
}

/* 
 * 
 * tabBox
 * 
 */

fInk.tabBox = {
	init: function(el){
		
		var $el = $(el);
		var $tabItems = $el.find('ul.tabItems')
		var $tabContent = $el.find('.tabContent .content');
		
		var preCurrent = $tabItems.find('.current');
		
		if(preCurrent.size() > 0){
			preCurrent = preCurrent.prevAll().size();			
		}
		else{
			preCurrent = 0;
		}
		
		$tabItems.tabs($tabContent, {
			initialIndex: preCurrent	
		});
	}
	
}

