//Browser Select
var css_browser_selector = function(){
    var ua = navigator.userAgent.toLowerCase(), is = function(t){
        return ua.indexOf(t) != -1;
    }, h = document.getElementsByTagName('html')[0], b = (!(/opera|webtv/i.test(ua)) && /msie (\d)/.test(ua)) ? ('ie ie' + RegExp.$1) : is('gecko/') ? 'gecko' : is('opera/9') ? 'opera opera9' : /opera (\d)/.test(ua) ? 'opera opera' + RegExp.$1 : is('konqueror') ? 'konqueror' : is('applewebkit/') ? 'webkit safari' : is('mozilla/') ? 'gecko' : '', os = (is('x11') || is('linux')) ? ' linux' : is('mac') ? ' mac' : is('win') ? ' win' : '';
    var c = b + os + ' js';
    h.className += h.className ? ' ' + c : c;
}();

//modified
//create the flash player
function createPlayer(playerTarget, file, coverImage){
    var flashvars = {
        file: file,
        image: coverImage,
        displayheight: 500
    };
    var params = {
        allowfullscreen: "true",
        allowscriptaccess: "always",
        menu: "false"
    };
    var attributes = {
        id: "player",
        name: "player"
    };
    if (document.getElementById('player')) {
        this.remove;
    };
    swfobject.embedSWF('/swf/player.swf', playerTarget, '950', '500', '9.0.115', false, flashvars, params, attributes);
};

jQuery(document).ready(function(){

    jQuery("ul.image_strip li a").hover(function(){
        jQuery(this).children('span.box').stop([]).animate({
            top: 0
        }, 300);
    }, function(){
        jQuery(this).children('span.box').stop([]).animate({
            top: 150
        }, 300, 'easeInOutExpo');
    });
    
    jQuery(".home_image ul li a").hover(function(){
        jQuery(this).children('span.box').stop([]).animate({
            top: 319
        }, 300, 'easeOutExpo');
    }, function(){
        jQuery(this).children('span.box').stop([]).animate({
            top: 470
        }, 300, 'easeInExpo');
    });
    
    //load  movies in the player
    jQuery('.sidebar_nav a[href$=".flv"]').click(function(){
        var file = jQuery(this).attr('href');
        var coverImage = jQuery(this).attr('rel');
        createPlayer('player', file, coverImage);
        return false;
    });
    
    //load pictures in the main viewing area
    jQuery('.sidebar_nav ul.image_strip li a').each(function(){
		var $this = $(this),
			target = $this.attr('href');
				
        $this.click(function(){
            if(target.match(/\.(gif|jpe?g|png|bmp)$/i)) {
				if (jQuery('.gallery_image img').attr('src') != target) {
	                jQuery('.gallery_image').addClass('loading');
	                
	                jQuery('.gallery_image img').hide().load(function(){
	                    jQuery(this).fadeIn();
	                    jQuery('.gallery_image').removeClass('loading');
	                }).attr({
	                    'src': target
	                });
				};
			}
            
            return false;
        });
    });
    
    //load pictures in the main viewing area
    jQuery('.project-options ul.image_strip li a').each(function(){
		var $this = $(this),
			target = $this.attr('href');
				
        $this.click(function(){
				if (jQuery('.project-image img').attr('src') != target) {
					
	                jQuery('.project-image').addClass('loading');
	                
	                jQuery('.project-image img').hide().load(function(){
	                    jQuery(this).fadeIn();
	                    jQuery('.project-image').removeClass('loading');
	                }).attr({
	                    'src': target
	                });
				};
            
            return false;
        });
    });
    
    //open images in lightbox
    jQuery('a[rel*="lightbox"]').lightBox({});
    
    //validate contact form
    jQuery('#contactForm').validate({
        rules: {
            name: {
                required: true
            },
            email: {
                required: true,
                email: true
            },
            enquiry: {
                required: true
            }
        }
    });
    
    //validate login form
    jQuery('#loginForm').validate({
        rules: {
            username: {
                required: true
            },
            password: {
                required: true
            }
        },
        messages: {
            username: {
                required: 'Please enter your username'
            },
            password: {
                required: 'Please enter your password'
            }
        }
    });
    
    //END THE JQUERY GOODNESS
});

jQuery.easing['jswing'] = jQuery.easing['swing'];

jQuery.extend(jQuery.easing, {
    def: 'easeOutQuad',
    swing: function(x, t, b, c, d){
        //alert(jQuery.easing.default);
        return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
    },
    easeInQuad: function(x, t, b, c, d){
        return c * (t /= d) * t + b;
    },
    easeOutQuad: function(x, t, b, c, d){
        return -c * (t /= d) * (t - 2) + b;
    },
    easeInOutQuad: function(x, t, b, c, d){
        if ((t /= d / 2) < 1) 
            return c / 2 * t * t + b;
        return -c / 2 * ((--t) * (t - 2) - 1) + b;
    },
    easeInExpo: function(x, t, b, c, d){
        return (t == 0) ? b : c * Math.pow(2, 10 * (t / d - 1)) + b;
    },
    easeOutExpo: function(x, t, b, c, d){
        return (t == d) ? b + c : c * (-Math.pow(2, -10 * t / d) + 1) + b;
    },
    easeInOutExpo: function(x, t, b, c, d){
        if (t == 0) 
            return b;
        if (t == d) 
            return b + c;
        if ((t /= d / 2) < 1) 
            return c / 2 * Math.pow(2, 10 * (t - 1)) + b;
        return c / 2 * (-Math.pow(2, -10 * --t) + 2) + b;
    }
});
