/***********************************************
***  BUTTON ROLLOVER & PRELOAD  ****************
************************************************/

$(function(){
	// button rollover
	if ($('.imgBtn') != null) {
		$('.imgBtn').hover(function(){
				if(!$(this).is('.disabled'))
					$(this).attr("src", $(this).attr("src").replace(/^(.*?)(?:-hover)?(\..*?)$/i,'$1-hover$2'));
			},
			function(){
					if(!$(this).is('.disabled'))
						$(this).attr("src", $(this).attr("src").replace(/^(.*)-hover(\..*?)$/i, '$1$2'));
				});
	}
	// preload image rollovers
	if ($("img.imgBtn, img[src^='images/buttons/btn'], input[src^='images/buttons/btn']") != null) {
	    $("img.imgBtn, img[src^='images/buttons/btn'], input[src^='images/buttons/btn']").each(function(){
			    $("<img>").attr("src", $(this).attr("src").replace(/(btn-.*)(\..*?)/i, '$1-hover$2'));
		    });
	}
});

/***********************************************
***  EXTERNAL LINKS  ***************************
************************************************/

$(document).ready(function() {
	$("a[rel=external]").each(function() {
		$(this).addClass('external');
		$(this).attr({
			title: "Open this page in a new window",
			target: "_blank"
		});
	})
});

/***********************************************
***  MENU BACKGROUND SLIDING  ******************
************************************************/

$(function(){
	$('#menu li a').hover(function(){
			$(this).stop().animate({
					backgroundPosition: '0 0'
				}, 200);
		},
		function(){
				$(this).stop().animate({
						backgroundPosition: '0 -35'
					}, 200);
			});
});

/***********************************************
***  HOME LOGO ROTATION  ***********************
************************************************/

$(function(){
	var delay = 4000;
	var fadeTime = 300;

	var curr = 1;

	function intFunc(){
		var prev = curr;
		curr++;
		
		$('.logosBox ul > li:nth-child(' + prev + ')').fadeOut(fadeTime, function(){
				$('.logosBox ul > li:nth-child(' + curr + ')').fadeIn(fadeTime, function(){
					});
			});
		if (curr == 3){
			curr = 1;
		}
	}
	var interval = window.setInterval(intFunc, delay);
});


/***********************************************
***  COMPACT FORM (LABEL OVER INPUT)  **********
************************************************/

$(function(){
	$('.compact input, .compact select, .compact textarea').focus(function(){
			$('label[for=' + $(this).attr('id') + ']').hide();
		});
	$('.compact input, .compact select, .compact textarea').each(function(ele){
			if($(this).val().length > 0)
				$('label[for=' + $(this).attr('id') + ']').css({ display: "none" });
		});
	$('.compact input, .compact select, .compact textarea').blur(function(){
			if($(this).val().length == 0)
				$('label[for=' + $(this).attr('id') + ']').show();
        });
    $('.compact label').each(function() {
        if ($(this).attr('title').length > 0)
            $(this).parent().addClass('error');
        });	
	$('.compact').removeClass('compact');
});


/***********************************************
***  CUFON  ************************************
************************************************/

$(function() {
	Cufon.replace('.homeHeading', { fontFamily: 'frutiger-cn' });
	Cufon.replace('p.homeIntro', { fontFamily: 'frutiger-cn' });
	Cufon.replace('.homeCol h3', { fontFamily: 'frutiger-cn-67' });
	Cufon.replace('.featuresList li', { fontFamily: 'frutiger-cn' });
	Cufon.replace('#main h1', { fontFamily: 'frutiger-cn' });
	Cufon.replace('#main h2', { fontFamily: 'frutiger-cn' });
	Cufon.replace('#sidebar .sidebarBox p.feature', { fontFamily: 'frutiger-cn' });
	Cufon.replace('#menu .tagLine', { fontFamily: 'frutiger-cn' });
	Cufon.replace('#menu li a', { fontFamily: 'frutiger-cn-67' });
	Cufon.replace('#sidebar h2', { fontFamily: 'frutiger-cn-67' });
	Cufon.replace('.logosBox h4', { fontFamily: 'frutiger-cn-67' });
	Cufon.replace('#menu li a', { fontFamily: 'frutiger-cn-67' });
    	Cufon.now();
    	
});

/***********************************************
***  PAGEFORM  *********************************
************************************************/

$(document).ready(function() {
    $(".pageForm li input, .pageForm li select, .pageForm li textarea").focus(function() {
        $(this).parent().addClass("focus");
    });
    $(".pageForm li input, .pageForm li select, .pageForm li textarea").blur(function() {
        $(this).parent().removeClass("focus");
    });
    $("span.errorMsg").each(function() {
        $(this).parent().addClass("error");
    });
});

/***********************************************
***  SWF OBJECT  *******************************
************************************************/

swfobject.embedSWF("flash/inc_titles.swf", "flashTitles", "700", "144", "8.0.0", "", {}, {wmode : "transparent"}, {});
swfobject.embedSWF("flash/publishers.swf", "publishersContainer", "656", "300", "8.0.0");
swfobject.embedSWF("flash/retailers.swf", "retailersContainer", "656", "300", "8.0.0");


swfobject.addDomLoadEvent(function() {
	$('.homeColsContainer').addClass('flashLoaded');
});
