$(function() {
		$( "html" ).disableSelection();
		
		var FullscreenrOptions = {  width: 2560, height: 1440, bgID: '#bgimg' };
		jQuery.fn.fullscreenr(FullscreenrOptions);
		
				
		if($.browser.msie){ //cause ie sux hard
			
			$("ul#icons li").css({'cursor':'default'});
		}else{
			window.setInterval(doPulse, 9000);

			$('#icons li,.maintitle,#qrcode div').draggable();	
			$(".maintitle").click(function(){
				$('#icons li,.maintitle,#qrcode div').animate({'top': '0px','left': '0px',	'position': 'relative'});
			});
		}
		
		$('.maintitle').fadeIn(function(){
			$("li").each(function(index) {
				$(this).delay(200*index).fadeIn(300);
	   		});
		})
		
		$('#qrcode').delay(7000).fadeIn(300);
		
		$("#bgimg").show();
		
		var number=2;
		$("li#work a").click(function () {
			if(number>5){number=1};
		    $("#bgimg").attr({src:"images/bg/image_" + number + ".jpg"});
		   	number+=1;
		});
		
		
		$('#pulse').css({'opacity':0});
		
		$.preLoadImages("images/bg/image_1.jpg","images/bg/image_2.jpg", "images/bg/image_3.jpg","images/bg/image_4.jpg","images/bg/image_5.jpg");		
		
	});
function doPulse() {  
		
		$('#pulse').pulse({
                opacity: [0,1]
            }, {
                times: 3,
                easing: 'swing',
                complete: function() {
        			$(this).animate({opacity:0});
    			}    
            })
            }


/**
* Fullscreenr - lightweight full screen background jquery plugin
* By Jan Schneiders
* Version 1.0
* www.nanotux.com
**/
(function($){	
	$.fn.fullscreenr = function(options) {
		if(options.height === undefined) alert('Please supply the background image height, default values will now be used. These may be very inaccurate.');
		if(options.width === undefined) alert('Please supply the background image width, default values will now be used. These may be very inaccurate.');
		if(options.bgID === undefined) alert('Please supply the background image ID, default #bgimg will now be used.');
		var defaults = { width: 1280,  height: 1024, bgID: 'bgimg' };
		var options = $.extend({}, defaults, options); 
		$(document).ready(function() { $(options.bgID).fullscreenrResizer(options);	});
		$(window).bind("resize", function() { $(options.bgID).fullscreenrResizer(options); });		
		return this; 		
	};	
	$.fn.fullscreenrResizer = function(options) {
		// Set bg size
		var ratio = options.height / options.width;	
		// Get browser window size
		var browserwidth = $(window).width();
		var browserheight = $(window).height();
		// Scale the image
		if ((browserheight/browserwidth) > ratio){
		    $(this).height(browserheight);
		    $(this).width(browserheight / ratio);
		} else {
		    $(this).width(browserwidth);
		    $(this).height(browserwidth * ratio);
		}
		// Center the image
		$(this).css('left', (browserwidth - $(this).width())/2);
		$(this).css('top', (browserheight - $(this).height())/2);
		return this; 		
	};
})(jQuery);


//preload function

(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)




/**
 * Pulse plugin for jQuery 
 * ---
 * @author James Padolsey (http://james.padolsey.com)
 * @version 0.1
 * @updated 16-DEC-09
 * ---
 * Note: In order to animate color properties, you need
 * the color plugin from here: http://plugins.jquery.com/project/color
 * ---
 * @info http://james.padolsey.com/javascript/simple-pulse-plugin-for-jquery/
 */

jQuery.fn.pulse = function( prop, speed, times, easing, callback ) {
    
    if ( isNaN(times) ) {
        callback = easing;
        easing = times;
        times = 1;
    }
    
    var optall = jQuery.speed(speed, easing, callback),
        queue = optall.queue !== false,
        largest = 0;
        
    for (var p in prop) {
        largest = Math.max(prop[p].length, largest);
    }
    
    optall.times = optall.times || times;
    
    return this[queue?'queue':'each'](function(){
        
        var counts = {},
            opt = jQuery.extend({}, optall),
            self = jQuery(this);
            
        pulse();
        
        function pulse() {
            
            var propsSingle = {},
                doAnimate = false;
            
            for (var p in prop) {
                
                // Make sure counter is setup for current prop
                counts[p] = counts[p] || {runs:0,cur:-1};
                
                // Set "cur" to reflect new position in pulse array
                if ( counts[p].cur < prop[p].length - 1 ) {
                    ++counts[p].cur;
                } else {
                    // Reset to beginning of pulse array
                    counts[p].cur = 0;
                    ++counts[p].runs;
                }
                
                if ( prop[p].length === largest ) {
                    doAnimate = opt.times > counts[p].runs;
                }
                
                propsSingle[p] = prop[p][counts[p].cur];
                
            }
            
            opt.complete = pulse;
            opt.queue = false;
            
            if (doAnimate) {
                self.animate(propsSingle, opt);
            } else {
                optall.complete.call(self[0]);
            }
            
        }
            
    });
    
};
