
// Main Scripts
// ----------------------------------------------------------------------------- //

// Link Scrubber Script
$(document).ready(function() {
	$("a").bind("focus",function(){if(this.blur)this.blur();});}
);


// Top Panel Toggle
$(function() {
	$("#top_panel").hide();
	$("a.dropdown_button").click(function () {
		$(this).toggleClass("dropdown_button_active");
		$("#top_panel").slideToggle(600);
		return false;
	});
});


// Main Menu Script
$(function() {

    $("nav ul li").hover(function(){
    
        $(this).addClass("hover");
        $("ul:first",this).slideDown(300);
    
    }, function(){
    
        $(this).removeClass("hover");
		$("ul:first",this).hide();
    
    });

});


// Main Image Rotator
$(function() {

	//Set Default State of each portfolio piece
	$("#paging").show();
	$("#paging a:first").addClass("active");
		
	//Get size of images, how many there are, then determin the size of the image reel.
	var imageWidth = $("#image_holder").width();
	var imageSum = $(".image_reel img").size();
	var imageReelWidth = imageWidth * imageSum;
	
	//Adjust the image reel to its new size
	$(".image_reel").css({'width' : imageReelWidth});
	
	//Paging + Slider Function
	rotate = function(){	
		var triggerID = $active.attr("id") - 1; //Get number of times to slide
		var image_reelPosition = triggerID * imageWidth; //Determines the distance the image reel needs to slide

		$("#paging a").removeClass('active'); //Remove all active class
		$active.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)
		
		//Slider Animation
		$(".image_reel").animate({ 
			left: -image_reelPosition
		}, 500 );
		
	}; 
	
	//Rotation + Timing Event
	rotateSwitch = function(){		
		play = setInterval(function(){ //Set timer - this will repeat itself every 3 seconds
			$active = $('#paging a.active').next();
			if ( $active.length === 0) { //If paging reaches the end...
				$active = $('#paging a:first'); //go back to first
			}
			rotate(); //Trigger the paging and slider function
		}, 7000); //Timer speed in milliseconds (3 seconds)
	};
	
	rotateSwitch(); //Run function on launch
	
	//On Hover
	$(".image_reel a").hover(function() {
		clearInterval(play); //Stop the rotation
	}, function() {
		rotateSwitch(); //Resume rotation
	});	
	
	//On Click
	$("#paging a").click(function() {	
		$active = $(this); //Activate the clicked paging
		//Reset Timer
		clearInterval(play); //Stop the rotation
		rotate(); //Trigger rotation immediately
		rotateSwitch(); // Resume rotation
		return false; //Prevent browser jump to link anchor
	});	
	
});


// Accordion List
$(function() {
	$(".accordionlist").accordion({
		active: true,
		autoheight: false,
		alwaysOpen: false
	});
});


// Column Image Rollovers
$(function() {
	$(".image_box img").fadeTo(1, 0.2);
	$(".column_one, .column_two, .column_three, .services_column_one, .services_column_two").hover(function(){
		$(".image_box img", this).stop().fadeTo(600, 1.0);
		},function(){
		$(".image_box img", this).stop().fadeTo(600, 0.2);
	});
	
});


// Twitter Feed$(function() {$("#twitter_feed").tweetable({username: 'dsb2004', time: true, limit: 3});}); ///


// Form Validate Script
$(function() {
	$("#emarketingForm").validate();
	$("#cushyForm").validate();
	$("#subForm").validate();
	$("#contactForm").validate();
});


// Scroll Script
$(function(){	
	// scroll to top
	$("a#topOfPage").click(function(){
		$.scrollTo( 0, 500);
		return false;
	});
	
});


// Latest Project Image Rollovers
//$(function() {
//	$(".image_box img").fadeTo(100, 0.2);
//	$(".image_box a").hover(function(){
//		$(this).children("img").stop().fadeTo("slow", 1.0);
//		},function(){
//		$(this).children("img").stop().fadeTo("slow", 0.2);
//	});
//	
//});



// Main Menu Script
//$(function() {
//    $(".column_three").hover(function(){
//        $(this).addClass("col_hover");
//    }, function(){
//        $(this).removeClass("col_hover");
//    });
//});



// Equal Column Height Script
//$(document).ready(function() {
//	$("#contents_container").equalHeights(); 
//});


// Minus Margin Click Box
//$(document).ready(function(){
//	$("#home").click(function() {
//		$("#right_col_contents").animate({
//				marginLeft: "0px"
//		}, 500);
//	});
//});


// No Right Click
//$(document).ready(function(){   
//	$("#header_logo").bind("contextmenu",function(e){
//		return false;
//	});
//	$("#contents_container").bind("contextmenu",function(e){
//		return false;
//	});
//	$(".news_image").bind("contextmenu",function(e){
//		return false;
//	});
//});	



//$(document).ready(function(){
//	$('div.webwork, div.logowork').hover(function(){
//			$(this).children('div.caption').stop().fadeTo(400, 1);
//	},function(){
//		$(this).children('div.caption').stop().fadeTo(600, 0);
//	});
//	
//	$('div.caption').hide();
//});



//$(document).ready(function(){
//	//Full Caption Sliding (Hidden to Visible)
//	$(".projectbox").hover(function(){
//		$(".project_caption", this).stop().animate({marginTop: '-30px'},{queue:false,duration:160});
//		$(this).fadeTo("slow", 1);
//
//	}, function() {
//		$(".project_caption", this).stop().animate({marginTop: '0'},{queue:false,duration:160});
//		$(this).fadeTo("slow", 0.8);
//
//	});			
//
//});
