$(document).ready(function(){
//number bg style
//by mouse coordinates
//$(document).mousemove(function(e){
//				$('#wh').html(e.pageX +', '+ e.pageY);
//});

//by window dimensions
//var bHeight = $(window).height();
//var bWidth = $(window).width();
//$("#wh").append(bWidth + "<br/>" + "X" + "<br/>" + bHeight);

//nav hover animation
$('#nav a').css( {backgroundPosition: "50% -52px"} )
				.mouseover(function(){
								$(this).stop().animate(
												{backgroundPosition:"(50% 0)"},
												{duration:400})
				})
				.mouseout(function(){
								$(this).stop().animate(
												{backgroundPosition:"(50% -52px)"},
												{duration:400})
				})

//hover effects
$('#logo').hover(
				function() {
								$(this).stop().animate(
												{backgroundPosition:"(-470 -24)"},
												{duration:500}																				
								);
				},
				function() {
								$(this).stop().animate(
												{backgroundPosition:"(-18 -24)"},
												{duration:500}
								);																
				}
);
$('#port').click(function() {
								$("body").css('border-top','1px solid #d2af33');
								//$(function() { makeBGmove(1); });
});
$('#about').click(function() {
								$("body").css('border-top','1px solid #336699');
								//$(function() { makeBGmove(1); });
});
$('#contact').click(function() {
								$("body").css('border-top','1px solid #b64412');
								//$(function() { makeBGmove(1); });
});
								
//cycle
//the stuff thats hidden will fade in the first slide
//$('#featured img:first').hide();
//$('#featured img:first').fadeIn(2000, function() {
				$('#featured').cycle({
							 fx: 'fade',
							 manualTrump: true,
								next: '.next',
				   	prev: '.prev',
							 pause: true,
							 pauseOnPagerHover: true,
							 delay: -2000,
							 timeout: 8000,
							 pager: '#featured_nav',
							 before: onBefore,
							 after: onAfter
				});
//});
				function onBefore() {
								$('#caption').slideToggle();
								//$('#slide_info').fadeOut();
				};
				function onAfter() {
							$('#caption').hide().html('<h3>' + this.title + '</h3>').slideToggle('slow');
							//var imgAlt = $(this).find('img').attr("alt");
							//$('#slide_info').hide().html('<p>' + imgAlt + '</p>').fadeIn('slow');
				};
				$('#main_content').cycle({ 
						fx: 'scrollHorz',
						easing:'backinout',
						manualTrump: true,
						pause: true,
						pauseOnPagerHover: true,
						timeout: 0,
						speed: 1000,
						cleartype:  true,
						fastOnEvent:   0,
						pagerEvent: 'click',
						pager:  '#nav',
						startingSlide: 0,
						pagerAnchorBuilder: function(idx, slide) {
										return '#nav li:eq(' + (idx) + ') a';
						}
				});
//end cycle code

//footer code					
$('.footer_bar').click(function(){
	$('.footer_box').slideToggle("slow");				
});
$(".footer_bar").toggle(
  function () {
    $('.opentoggle').addClass("closetoggle");
    $('#featured').cycle('pause');
  },
  function () {
    $('.opentoggle').removeClass("closetoggle");
    $('#featured').cycle('resume');
  }
);
$('a#footer_logo').fadeTo("fast", 0.3);
$('a#footer_ugly').fadeTo("fast", 0.3);
$('a#footer_logo, a#footer_ugly').hover(
	function() {
					$(this).stop().animate({
						opacity:".8"
					});
				},
	function() {
			  $(this).stop().animate({
						opacity:".3"
					});															
				}
);
$('.footer_bar').fadeTo("fast", 0.3);
$('.footer_bar').hover(
	function() {
					$(this).stop().animate({
						opacity:"0.9"
					});
				},
	function() {
			  $(this).stop().animate({
						opacity:"0.3"
					});															
				}
);
//end footer code

function validateme() {
	$("#contact_form").validate();
}

//submit contact form
var options = {
				url:        'send_message.php',
				beforeSubmit: validate,
 			success:    function() {
								$('#messagenotsent').hide('fast');
								$('.message_box').css('background','#590');
								$('#messagesent').show('fast');
								$('#contact_form').clearForm();
								setTimeout('$("#messagesent").hide();$(".message_box").css("background","none")', 5000);
				}
};
$('#contact_form').ajaxForm(options);

//validation - to be beefed up
function validate(formData, jqForm, options) { 
				for (var i=0; i < formData.length; i++) { 
								if (!formData[i].value) {
												$('.message_box').css('background','#f90');
												$('#messagenotsent').show('fast');
												alert('Please fill in all fields');
												return false; 
								} 
				} 
//alert('Both fields contain values.');
}

//colorbox
//outside webpage
$(".outsidesite").colorbox({
				width:"90%", 
				height:"90%",
				onOpen: function() {
							$('#featured').cycle('pause');
				},
				onClosed: function() {
								$('#featured').cycle('resume');
				},
				onComplete: function() {
								$('#cboxTitle').prepend("<span class=\"red_love\">" + "&raquo; " + "</span>" ); 
				},
				iframe:true
});
//images
$("a[rel='examples']").colorbox({
				current: "{current} of {total}",
				onOpen: function() {
								$('#featured').cycle('pause');
				},
				onClosed: function() {
								$('#featured').cycle('resume');
				},
				onComplete: function() {
								$('#cboxTitle').prepend("<span class=\"red_love\">" + "&raquo; " + "</span>" ); 
				}	
});

//current year for copywrite
var currentYear = (new Date).getFullYear();
$('#cur_year').text( (new Date).getFullYear() );

//playing with moving body background
//window.setInterval(function(index){
//$(function() { makeBGmove(1); });
//},5000);
function makeBGmove() {
        var bPos = $('body').css('background-position');
        bPos = bPos.replace(/px/g, '').split(' ');
        bPos = (-3600 + parseInt(bPos[0], 0)) + 'px ' + bPos[1] + 'px';
        $('body').stop().animate({"background-position" : bPos},'fast');
				}

});