jQuery.noConflict();

jQuery(document).ready(function(){
	// activates the lightbox page, if you are using a dark color scheme use another theme parameter
	k_smoothscroll();
	k_menu(); // controls the dropdown menu
	

	
	
	var selectImg = '#main';
	if (jQuery.browser.msie) selectImg = '.portfolio_item, .image_border'
	jQuery(selectImg).kriesi_image_preloader({delay:200});	// activates preloader for non-slideshow images
});



// -------------------------------------------------------------------------------------------
// input field improvements
// -------------------------------------------------------------------------------------------




	
// -------------------------------------------------------------------------------------------
// The Image preloader
// -------------------------------------------------------------------------------------------


(function($)
{
	$.fn.kriesi_image_preloader = function(options) 
	{
		var defaults = 
		{
			repeatedCheck: 500,
			fadeInSpeed: 1000,
			delay:600,
			callback: ''
		};
		
		var options = $.extend(defaults, options);
		
		return this.each(function()
		{
			var imageContainer = jQuery(this),
				images = imageContainer.find('img').css({opacity:0, visibility:'hidden'}),
				imagesToLoad = images.length;				
				
				imageContainer.operations =
				{	
					preload: function()
					{	
						var stopPreloading = true;
						
						images.each(function(i, event)
						{	
							var image = $(this);
							
							
							if(event.complete == true)
							{	
								imageContainer.operations.showImage(image);
							}
							else
							{
								image.bind('error load',{currentImage: image}, imageContainer.operations.showImage);
							}
							
						});
						
						return this;
					},
					
					showImage: function(image)
					{	
						imagesToLoad --;
						if(image.data.currentImage != undefined) { image = image.data.currentImage;}
												
						if (options.delay <= 0) image.css('visibility','visible').animate({opacity:1}, options.fadeInSpeed);
												 
						if(imagesToLoad == 0)
						{
							if(options.delay > 0)
							{
								images.each(function(i, event)
								{	
									var image = $(this);
									setTimeout(function()
									{	
										image.css('visibility','visible').animate({opacity:1}, options.fadeInSpeed);
									},
									options.delay*(i+1));
								});
								
								if(options.callback != '')
								{
									setTimeout(options.callback, options.delay*images.length);
								}
							}
							else if(options.callback != '')
							{
								(options.callback)();
							}
							
						}
						
					}

				};
				
				imageContainer.operations.preload();
		});
		
	}
})(jQuery);





function k_menu()
{
	// k_menu controlls the dropdown menus and improves them with javascript
	
	jQuery("#nav a").removeAttr('title');
	jQuery(" #nav ul").css({display: "none"});
	
	//smooth drop downs
	jQuery("#nav li").each(function()
	{	
		var $sublist = jQuery(this).find('ul:first');
		
		$sublist.find('>li:first').css('marginTop','5px');
		$sublist.find('>li:last').css('marginBottom','5px');
		
		jQuery(this).hover(function()
		{	
			$sublist.stop().css({overflow:"hidden", height:"auto", display:"none",'paddingTop':'0px','paddingBottom':'0px'}).slideDown(400, function()
			{
				jQuery(this).css({overflow:"visible", height:"auto"});
			});
		},
		function()
		{	
			$sublist.stop().slideUp(400, function()
			{	
				jQuery(this).css({overflow:"hidden", display:"none"});
			});
		});	
	});
}


//equalHeights by james padolsey
jQuery.fn.equalHeights = function() {
    return this.height(Math.max.apply(null,
        this.map(function() {
           return jQuery(this).height()
        }).get()
    ));
};








function k_smoothscroll()
{
	jQuery('a[href*=#]').click(function() {
		
	   // duration in ms
	
	   var newHash=this.hash,
		   target=jQuery(this.hash).offset().top,
		   oldLocation=window.location.href.replace(window.location.hash, ''),
		   newLocation=this,
		   duration=800,
		   easing='easeOutQuint';
		
		
	   // make sure it's the same location      
	   if(oldLocation+newHash==newLocation)
	   {
	      // animate to target and set the hash to the window.location after the animation
	      jQuery('html:not(:animated),body:not(:animated)').animate({ scrollTop: target }, duration, easing, function() {
	
	         // add new hash to the browser location
	         window.location.href=newLocation;
	      });
	
	      // cancel default click action
	      return false;
	   }
	
	});
}

function homeslide(){
// Set Script Options
var options = {
	"id":		'container', // Required ID
	"type": "slideout",
	"width":	754,//			Required Width
	"height":	265,//			Required Height
	"delay":	5000,//			Optional Delay
	"speed":	400,//			Optional Speed
	"steps":	6,//			Optional Steps
	"onstart":	function(c,l){//Optional OnStart Callback Function
					//Change the class of the controls to reflect which slide is active
					c_div= document.getElementById('control_wrap');
					divs=c_div.getElementsByTagName('div');
					divs[l].className='control_inactive';
					divs[c].className='control_active';
				}
};		


///////////////////////////
// Initialize The slider //
///////////////////////////
var sc= new dropandscroll(options);
sc.st();


var c_div=document.getElementById('control_wrap');
c_div.style.position="relative";
c_div.style.top=-(options.height)+"px";
c_div.style.left="0px";
c_div.style.zIndex=10000;


//Add onclick event handlers to the controls
var divs=c_div.getElementsByTagName('div');
for(i=0;i<divs.length;i++){
	divs[i].num=i;
	divs[i].onmouseover=function(){sc.gt(this.num+1);};
}

sc.ti=setTimeout(sc.pl,sc.del);


}






