$(document).ready(function(){
	/* agent = navigator.userAgent;
	iPad = agent.search(/iPad/i);
	
	if (iPad > 0){
		$('#index #flash-banner').hide();
		$('#index #flash #ipad video, #index #flash #ipad').show();
		// alert('hello ipad user');
	} */
	
	if ($('#index').length > 0){		
		$('#bow-small')
			.click(
				function(){
					$('#bow-content, #bow-small').hide();
					$('#bow-huge').fadeIn();
					$('#content').css('top','1170px');
					$('#top-banner').css('height','1044px');
					
					return false;
				}
			)
		
		$('#bow-huge')
			.click(
				function(){
					$('#bow-content, #bow-small').fadeIn();
					$('#bow-huge').hide();
					$('#content').css('top','450px');
					$('#top-banner').css('height','356px');
					
					return false;
				}
			)
	}
	
	$('li.dd')
		.hover(
			function(){
				$('a#hovered').removeAttr('id');
				x = $(this).attr('rel');
				$('a[rel='+x+']').attr('id','hovered');
				$('#login').hide();
				$('ul[rel='+x+']').show();
				$('#header').css('height','325px');
			},
			function(){
				x = $(this).attr('rel');
				$('a[rel='+x+']').removeAttr('id');
				$('ul[rel='+x+']').hide();
				$('#header').css('height','auto');
			}
		);
	
	$('li.dd ul li a')
		.hover(
			function(){
				$(this)
					.animate({
						backgroundColor: '#667a9d'
					}, {queue:false}, 100)
			},
			function(){
				$(this)
					.animate({
						backgroundColor: '#fff'
					}, {queue:false}, 300)
			}
		);
	
	$('#close')
		.click(
			function(){
				$('#ie6').hide();
				$('#header').css('top','0');
				
				return false;
			}
		);
	
	$('#publogin')
		.submit(
			function(){
				id = $(this).attr('id');
				username = $('#'+id+' input[name=UserName]').val();
				password = $('#'+id+' input[name=Password]').val();
				
				if (username == '' || password == ''){
					$('.alerts').html('Please fill in your username/password.').fadeIn();
				} else {
					$.ajax({
						url: "../publogin.cfm",
						data: {username:username,password:password},
						success: function(data){
							data = (data).replace(/^\s*|\s*$/g,'');
							
							if (data == 0){
								$('.alerts').html('Username/password are not found.').fadeIn();
							}
							
							if (data == 1){
								window.location = ("../publisher/loginverify.cfm?username="+username+"&password="+password);
							}
							
							if (data == 2){
								window.location = ("http://www.wrightsprinting.com/clients/loginverify.cfm?username="+username+"&password="+password);
							}
						}
					})
				}
				
				
				return false;
			}
		)
	
	if ($('.fancy').length > 0){
		$('.fancy').fancybox();
		
		$('.iframe').fancybox({
			'width':'90%',
			'height':'90%',
			'autoScale':false
		})
	};
	
	if ($('#contact-form').length > 0){
		$('#contact-form')
			.submit(
				function(){
					fname = $('input[name=first]').val();
					lname = $('input[name=last]').val();
					comp = $('input[name=company]').val();
					if ($('input[name=magazineName]').length > 0){
						magname = $('input[name=magazineName]').val();
					} else {
						magname = '';
					}
					email1 = $('input[name=email1]').val();
					email2 = $('input[name=email2]').val();
					phone = $('input[name=phone]').val();
					publisher = $('input[name=publisher]').val();
					message = $('textarea[name=message]').val();
					
					spam1 = $('label[for=spamBlock]').text();
					spam2 = $('input[name=spamBlock]').val();
					
					alerts = '';
					
					if (fname == '' || lname == '' || comp == '' || email1 == '' || phone == '' || publisher == ''){
						alerts = 'Please fill in all fields.<br />';
					}
					
					if (email1 !== email2){
						alerts += 'Please be sure emails match so we can get ahold of you.<br />';
					}
					
					if (spam1 !== spam2){
						alerts += 'Please check the spam blocker entry.';
					}
					
					if (alerts !== ''){
						$('.alerts').html(alerts).fadeIn();
					} else {
						$('.alerts').fadeOut().html('');
						
						return true;
					}
					
					return false;
				}
			)
	}
	
	if ($('#video-play').length > 0){
		$('#video-play').click(
			function(){
				$('#video').load('video.cfm');
				
				return false;
			}
		)
	}
});
