$(document).ready(function() {
    /* jquery commands here */

	
	// Disable right click on images
    $(document).bind("contextmenu",function(e){
		if(e.target.tagName == 'IMG'){
			//alert("Sorry, we do not allow right-clicking on images.");
			return false;
		}
    });

	
	
    $('#superbgimage').superbgimage().hide();

    $.fn.supersized.options = {
        startwidth: 640,
        startheight: 480,
        vertical_center: 1,
        slideshow: 1,
        navigation: 0,
        transition: 1,  //0-None, 1-Fade, 2-slide top, 3-slide right, 4-slide bottom, 5-slide left
        pause_hover: 1,
        slide_counter: 1,
        slide_captions: 1,
        slide_interval: 10000
    };

    $('#supersize').supersized();

    $('.thumbnail img').click(function() {
		
		// This function by Jesse Bunch
		
		var strSRC = $(this).attr("id");
		
		// Object references
		var objThumb = $(this);
		var objBigImg = $("#large-portfolio");
		var objLi = objThumb.parent().parent();
		
		// Check to see if user is already viewing this image
		if (strSRC == objThumb.attr("src")) {
			return;
		}
		
		// Get the title from the thumbnail (its transferred to the big img)
		var strImgTitle = objThumb.parent('a').attr("id");

		
		// Show AJAX loader	
		objLi.css("background-repeat", "no-repeat");
		objLi.css("background-position", "37px 37px")
		objLi.css("background-image", "url(/css/img/ajax-loader.gif)");
		
		objThumb.animate({opacity: 0.5}, 500, function() {
			
				// Fade out current image
				objBigImg.animate({opacity: 0.0}, 500, function() {

					// Get the next image's dimensions
					$.ajax({
			            url: "/scripts/calc_dimensions.php",
			            type: "POST",
			            data: ({
			            	type : 'max_dims',
							src: strSRC,
							width: 570,
							height: 525  
			            }),
						dataType: 'json',
			            success: function(data) {

							// Check for server-side errors
			                if (data.error == null) {
								
								
								// Modify the query string to prevent caching in IE 7 & 8
								if ($.browser.msie && $.browser.version.substr(0,1)>=7) {
									strSRC = strSRC + "?&random=" + Math.round(Math.random()*9999999);
								}
								
								
								// No error, so swap out the image and size it up correctly
								objBigImg.attr("src", strSRC).load(function(){
									
									// Set the image's width and height based on data received from the PHP script
									objBigImg.attr("width", data.width);
									objBigImg.attr("height", data.height);
									
									// Set mouseover title
									objBigImg.attr("title", strImgTitle);

									// Fade the main image back in
									objBigImg.animate({opacity: 1.0}, 500, function() {
										
										// Remove the loader
										objThumb.animate({opacity: 1.0}, 250);

									});
								});
							}
			            },
						error: function(objRequest, strStatus, objErrorThrown) {
                            return;
							// alert("Error: " + objRequest.statusText);
						}
			        });	        
				});
		});
		
		return false;
    });

    setTimeout(function() {
        $('#home #sub-menu').animate({
            "left": "-15px"
        },
        "1000");
    },
    2000);

});
