// JavaScript Document
YAHOO.namespace("ozmosis");

YAHOO.ozmosis.initJScroll = function(e){
	
	if(YAHOO.util.Dom.get("right-pane") != null  && YAHOO.util.Dom.get("scroll-pane") != null){
	
		YAHOO.util.Dom.setStyle("scroll-pane", "overflow", "hidden");
		YAHOO.util.Dom.setStyle("right-pane", "overflow", "hidden");	
		$(function() {
			$('#scroll-pane').jScrollPane({dragMinHeight:53, dragMaxHeight:53, scrollbarWidth:12});
		});
	
	}
}
YAHOO.ozmosis.removeJScroll = function(e){
	
	if(YAHOO.util.Dom.get("scroll-pane") != null){
		$(function() {
			$('#scroll-pane').jScrollPaneRemove();
		});
	}
}

YAHOO.ozmosis.skinSwitch = function(e, o){
	
//	if(YAHOO.util.Dom.getViewportWidth() < 1100){	
//		if(!YAHOO.util.Dom.hasClass(document.body, "normal")){
//			YAHOO.util.Dom.removeClass(document.body, "widescreen");
//			YAHOO.util.Dom.addClass(document.body, "normal");
//			YAHOO.ozmosis.removeJScroll();
//			YAHOO.ozmosis.initJScroll();
//		}	
//	}
//	else {
		  if(!YAHOO.util.Dom.hasClass(document.body, "widescreen")){
			  YAHOO.util.Dom.removeClass(document.body, "normal");	
			  YAHOO.util.Dom.addClass(document.body, "widescreen");	
			  YAHOO.ozmosis.removeJScroll();
			  YAHOO.ozmosis.initJScroll();
		  }	
//	}
//	
}

YAHOO.util.Event.on(window, "resize", YAHOO.ozmosis.skinSwitch);
YAHOO.util.Event.onDOMReady(YAHOO.ozmosis.skinSwitch);

// Google Maps Geocode and Location
YAHOO.ozmosis.initGoogleMap = function(ll) {

    if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById(ll.element));
        var geocoder = null;
        geocoder = new GClientGeocoder();


        //		  if (ll.address) {
        //	
        //		    if (geocoder) {geocoder.getLatLng(ll.address,
        //          		function(point) {					
        //					map.setCenter(point, 13);
        //					var marker = new GMarker(point);
        //					map.addControl(new GSmallMapControl());
        //        	        map.addControl(new GMapTypeControl());
        //              		map.addOverlay(marker);          	    
        //				});
        //      	    }
        //		  }
        if (ll.address) {
            
            var lat = ll.address.split(",")            
            map.setCenter(new GLatLng(lat[0],lat[1]), 13);
            var marker = new GMarker(new GLatLng(lat[0], lat[1]));
            map.addControl(new GSmallMapControl());
            map.addControl(new GMapTypeControl());
            map.addOverlay(marker);
        }
    }
}

YAHOO.ozmosis.initGallery = function(){
	
	// Get all main gallery photos - The large ones
	var mainImageContainer = YAHOO.util.Dom.get("bio-media-content-two-a");
	
	// Check that it has our classname of "photos" so we know we are on the photos page
	// If it does then we can continue and setup out gallery function
	if(YAHOO.util.Dom.hasClass(mainImageContainer, "photos")){
		
		// Gather all child imgs
		var mainImages = YAHOO.util.Dom.getChildrenBy(mainImageContainer, checkForImage);

		// Gather all thumbnails
		var thumbnails = YAHOO.util.Dom.getChildren("media-thumbs");
		
		// Check that we have the same number of images and thumbnails
		// The script won't do anything unless they are the same :)
		if(mainImages.length === thumbnails.length){
			
			// Setup inital id to the 1st image to visible
			YAHOO.util.Dom.setAttribute(mainImages[0], "id", "visible");
			
			// Setup our animation
			var show = {opacity: {from: 0, to: 1 }};
			var hide = {opacity: {from: 1, to: 0 }};
		
			// Function to test that passed object has a tag name of img
			var checkForImage = function(o){
				if(o.tagName === "IMG"){
					return true;	
				}
				else { return false;}
			};
			
			var switchImage = function(e, o){
				
				// Stop default
				YAHOO.util.Event.stopEvent(e);
				
				var currentImage = YAHOO.util.Dom.get("visible");
				
				// Only if the image is not the SAME
				if(currentImage != o.mainImage){
	    		
					var anim  = new YAHOO.util.Anim(o.mainImage, o.show, 0.5, YAHOO.util.Easing.easeOut); 
					var anim2 = new YAHOO.util.Anim(currentImage, o.hide, 0.5, YAHOO.util.Easing.easeOut); 
					
					YAHOO.util.Dom.setAttribute(o.mainImage, "id", "visible");
					//YAHOO.util.Dom.setStyle(o.mainImage, "z-index", "9999999");
					
					YAHOO.util.Dom.setAttribute(currentImage, "id", "");
					//YAHOO.util.Dom.setStyle(currentImage, "z-index", "1");
					
					anim.animate();
					anim2.animate();
				}
				
			}
			
			// Add click handler to our thumbnails
			var i=0;
			for(i=0;i<=thumbnails.length;i++){
				YAHOO.util.Event.on(YAHOO.util.Dom.getFirstChild(thumbnails[i]), "click", switchImage, {"mainImage":mainImages[i], "show":show, "hide":hide});
				if(i != 0){
					YAHOO.util.Dom.setStyle(mainImages[i], "opacity", 0);
				}
			}
		
		} // END if same photos/thumbnails check
	
	}
	
}

YAHOO.util.Event.onDOMReady(YAHOO.ozmosis.initGallery);




////////////// Disable right click on images only for all kinds of browsers ////////////

var clickmessage = "Right click disabled on images!"
function disableclick(e) {
    if (document.all) {
        if (event.button == 2 || event.button == 3) {
            if (event.srcElement.tagName == "IMG") {
                alert(clickmessage);
                return false;
            }
        }
    }
    else if (document.layers) {
        if (e.which == 3) {
            alert(clickmessage);
            return false;
        }
    }
    else if (document.getElementById) {
        if (e.which == 3 && e.target.tagName == "IMG") {
            alert(clickmessage)
            document.oncontextmenu = new Function("return false")
        }
        else document.oncontextmenu = new Function("return true")
    }
}
function associateimages() {
    for (i = 0; i < document.images.length; i++)
        document.images[i].onmousedown = disableclick;
}
if (document.all)
    document.onmousedown = disableclick
else if (document.getElementById)
    document.onmouseup = disableclick
    
else if (document.layers)
    associateimages()

/////////////////////////////////end          //////////////////////

