Shadowbox.loadSkin('classic', '../js/src/skin');
Shadowbox.loadLanguage('en', '../js/src/lang');
Shadowbox.loadPlayer(['flv', 'html', 'iframe', 'img', 'qt', 'swf', 'wmp'], '../js/src/player');

$(document).ready(function(){
						   
	h = $('#wrapper').height()+12;
	$('#media-expo').css('height',h);
						   
	$('#media-expo #info').load("mediaexpo/2009/index.html");
	
	s = 14;
	
	updateText = setInterval(
		function(){
			$('a#skip').text('To skip this ad, click here, or wait '+s+' seconds.');
			s--;
		}, 1000);
	
	$('#skip')
		.click(
			function(){
				$('#media-expo')
					.hide();
					clearInterval(updateText);
				return false;
			}
		);
	$('#media-expo')
		.animate({
				opacity: 1
			}, 15000, function()
				{
					$(this).hide();
					clearInterval(updateText);
				});
	
	$('a#media-expo-link')
		.click(
			function(){
				$('a#skip').text('Click here to close ad.');
				$('#media-expo').show();
				
				return false;
			}
		);
	
	$('.gbutton').hover(
		function(){
			$(this)
				.children()
				.fadeIn()
				.animate({bottom: '75px'}, {queue: false});
		},
		function(){
			$(this)
				.children()
				.fadeOut()
				.animate({bottom: '70px'}, {queue: false});
		}
	);
	
	Shadowbox.init();
	
	$("a.media").media({width:935, height:525});

	$(".box").hover(
		function(over){
			$(this).css("border-top","#888 1px solid");
			$(this).css("border-left","#888 1px solid");
			$(this).css("border-right","#888 1px solid");
			$(this).css("border-bottom","#888 1px solid");
		},
					   
		function(out){
			$(this).css("border-top","#fff 1px solid");
			$(this).css("border-left","#fff 1px solid");
			$(this).css("border-right","#fff 1px solid");
			$(this).css("border-bottom","#ccc 1px solid");
		}
	);
	
	$(".equip").hover(
		function(over){
			$(this).css("background","#eee");
			$(this).css("color","#000");
		},
					   
		function(out){
			$(this).css("background","#fefefe");
			$(this).css("color","#333");
		}
	);
	
	$("#awards-list a").hover(
		function(over){
			$(this).animate({backgroundColor:"#fff"}, 500);
		},
					   
		function(out){
			$(this).animate({backgroundColor:"#ccc"}, 500);
		}
	);
	
	$("#awards-text").click(
		function(){
			var txt = $(this).text();
			
			if (txt !== "close awards list"){
				$("#awards-tab").animate({top:"80px"},1500);
				$("#awards-list").animate({top:"80px"},1500);
				$("#awards-text").animate({top:"466px"},1500);
				$("#awards-text").html("close awards list");
			} else {
				$("#awards-tab").animate({top:"-193px"},1500);
				$("#awards-list").animate({top:"-193px"},1500);
				$("#awards-text").animate({top:"193px"},1500);
				$("#awards-text").html("view awards won");
			}
		}
	);
	
	$('#topBannerProducts #slideShow').innerfade({ timeout: '6000', type: 'sequence', containerheight: '398px' });
	
	$("#name, #email, #verify-email").defaultvalue("(required)", "(required)", "(required)");
	
	if ($('#message').text() == ''){
		$("#message").defaultvalue("Please type a short description of how we can help you.");
	};
	
	$("input").focus(
		function(){
			if ($(this).attr('class') !== 'no-animation'){
				$(this).animate({backgroundColor:"#fff", color:"#000"}, 500);
			}
		}
	);
	
	$("#name, #email").blur(
		function(){
			var rText = $(this).val();
			
			if (rText == ""){
				$(this).animate({backgroundColor:"#BF0D1C", color:"#fff"}, 500);
			};
			
			if (rText !== ""){
				$(this).animate({backgroundColor:"#9EFF97", color:"#000"}, 500);
			};
		}
	);
	
	$("#verify-email").blur(
		function(){
			var e = $("#email").val();
			var ev = $("#verify-email").val();
			
			if (ev == ""){
				$(this).animate({backgroundColor:"#BF0D1C", color:"#fff"}, 500);
				$(this).defaultvalue("(required)");
			} else if (e == ev){
				$(this).animate({backgroundColor:"#9EFF97", color:"#000"}, 500);
			} else {
				$(this).animate({backgroundColor:"#BF0D1C", color:"#fff"}, 500);
				$(this).defaultvalue("emails must match");
			}
		}
	);
	
	$("#contactForm")
		.submit(
			function(){
				n = $("#name").val();
				e = $("#email").val();
				ev = $("#verify-email").val();
				comp = $('#company').val();
				phone = $('#phone').val();
				mess = $('#message').val();
				error = '';
				
				if (n == "(required)" || e == "(required)" || ev == "(required)"){
					error += 'Please fill in the required fields.<br />';
				} else if (e != ev){
					error += 'Please enter matching email address.';
				}
				
				if (error != ''){
					$('.alerts')
						.html(error)
						.fadeIn()
						.animate({
							opacity: 1
						}, 6000)
						.fadeOut();
				} else {
					$.ajax({
						   url: "contact-submit.cfm",
						   data: {name:n, company:comp, email:e, phone:phone, message:mess, sendrequest:'yes', important:''},
						   success: function(){
							   $('.alerts').html('Thank you for contacting Wright\'s Reprints.<br />We will be in touch shortly.<br /><br /><a href="index.cfm">reset form</a>').fadeIn();
						   }
						});
				}
				
				return false;
			}
		);
	
	var formStatus = $("#form-status").text();
	
	if (formStatus == "yes"){
		$("#successful").show();
		$("#form-content").hide();
	};
	
	$('h1.title')
		.click(
			function(){
				if ($(this).children('span').html() === '[+]'){
					$(this).next().slideDown();
					$(this).children('span').html('[-]');
				} else {
					$(this).next().slideUp();
					$(this).children('span').html('[+]');
				}
			}
		);
	
	if ($('#contactForm').length > 0){
		// $("#contactForm").validationAideEnable(null, {showInlineMessages:true, inlineShowSpeed:"fast"});
	};
	
	if ($('body#postcard').length > 0){
		
		// SETTING NUMBERS FOR ROI
		num1 = 1;
		num2 = 3;
		$('#roi').attr('value',(num1+'-'+num2+'%'));
		
		$('a[rel=variable], a[rel=purl]').attr('num1','10').attr('num2','15');
		$('a[rel=bar-codes]').attr('num1','5').attr('num2','5');
		$('a[rel=qrcodes]').attr('num1','0').attr('num2','0');
		
		// TAB NAVIGATION
		$('#tabNav a')
			.click(
				function(){
					id = $(this).attr('href');
					id = id.substring(1,id.length);
					
					$('.selected').removeAttr('class');
					$(this).attr('class','selected');
					
					$('#tabContent li').hide();
					$('#'+id).fadeIn();
					if ($('a[href=#bt-'+id+']').attr('id') !== 'selected' && id !== 'tab1'){
						name = $('a[href=#bt-'+id+']').attr('rel');
						$('a[href=#bt-'+id+']').attr('id','selected');
						
						if (num1 == 1){
							num1 = 0;
							num2 = 0;
						}
						
						addnum1 = parseInt($('a[rel='+name+']').attr('num1'));
						addnum2 = parseInt($('a[rel='+name+']').attr('num2'));
						num1 = num1+addnum1;
						num2 = num2+addnum2;
							
						if (num1 == 5){
							$('#roi').attr('value',('5%'));
						} else {
							$('#roi').attr('value',(num1+'-'+num2+'%'));
						}
						
						if ($('a[href=#bt-'+name+']').attr('class') == 'control var'){
							title = $('#pc-'+name).attr('title');
							if (name == 'variable'){
								$('#pc-'+name).text('Bill, '+title);
							} else {
								$('#pc-'+name).text('Find out more at bill.wrightsmedia.com');
							}
						} else {
							$('#pc-'+name).show();
						}
					}
					
					
					return false;
				}
			);
		
		
		// CONTROLS TO SWITCH THE POSTCARD OPTIONS ON/OFF
		$('#controls a')
			.click(
				function(){
					id = $(this).attr('rel');
					tab = $(this).attr('href');
					tab = tab.substring(4,tab.length);
					
					if (num1 == 1){
						num1 = 0;
						num2 = 0;
					}
					
					addnum1 = parseInt($(this).attr('num1'));
					addnum2 = parseInt($(this).attr('num2'));
					
					if ($(this).attr('id') !== 'selected'){
						$(this).attr('id','selected');
						
						if ($(this).attr('class') == 'control var'){
							title = $('#pc-'+id).attr('title');
							if (id == 'variable'){
								$('#pc-'+id).text('Bill, '+title);
							} else {
								$('#pc-'+id).text('Find out more at bill.wrightsmedia.com');
							}
						} else {
							$('#pc-'+id).show();
						}
						
						num1 = num1 + addnum1;
						num2 = num2 + addnum2;
					} else {
						
						if ($(this).attr('class') == 'control var'){
							title = $('#pc-'+id).attr('title');
							$('#pc-'+id).text(title);
						} else {
							$('#pc-'+id).hide();
						}
						
						$(this).removeAttr('id');
						
						num1 = num1 - addnum1;
						num2 = num2 - addnum2;
					}
						
						$('.selected').removeAttr('class');
						$('a[href=#'+tab+']').attr('class','selected');
						$('#tabContent li').hide();
						$('#'+tab).fadeIn();
					
					if (num1 == 0){
						num1 = 1;
						num2 = 3;
						
						if ($('a[rel=qrcodes]').attr('id') !== 'selected'){
							$('.selected').removeAttr('class');
							$('a[href=#tab1]').attr('class','selected');
							$('#tabContent li').hide();
							$('#tab1').fadeIn();
						}
						
					}
					
					if (num1 == 5){
						$('#roi').attr('value',('5%'));
					} else {
						$('#roi').attr('value',(num1+'-'+num2+'%'));
					}
					
					return false;
				}
			);
	};
	
	if ($('table#card-pricing td').length > 0){
		$('table#card-pricing tbody tr td')
			.hover(
				function(){
					$(this).parent().css('background','#B1C2FE');
				},
				function(){
					$(this).parent().css('background','#fff');
				}
			)
	}
});