/**
 * GLOBAL.JS
 * 
 */
	
var TestBrowser = function (_property){
		return ( $('html').hasClass( _property ) ) ? true : false;
	};
	
var Cookie = {
		set: function(c_name, value, expiredays) {
	        var exdate = new Date();
	        exdate.setDate(exdate.getDate() + expiredays);
	        document.cookie = c_name + "=" + escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toUTCString()+";path=/");
	    },
		get: function(c_name) {
	        if (document.cookie.length > 0) {
	            c_start = document.cookie.indexOf(c_name + "=");
	            if (c_start != -1) {
	                c_start = c_start + c_name.length + 1;
	                c_end = document.cookie.indexOf(";", c_start);
	                if (c_end == -1) c_end = document.cookie.length;
	                return unescape(document.cookie.substring(c_start, c_end));
	            }
	        }
	        return "";
		},
		erase: function(name){
			this.set(name, '', -1);
		}
	};

var Toggle = function (_config) {
		var config = _config || false;
		var container = (config.hasOwnProperty('container')) ? config.container : '.toggle_content',
			button = (config.hasOwnProperty('button')) ? config.button : '.toggle_link';
		({
			style_nodes: function () {
				// Loop through the containers.
				for(var i = 0; i < $(container).length; i += 1) {
					if( Cookie.get('active_link') ) {
						if( $(container).eq(i).prop('id') !== Cookie.get('active_link') ){
							$(container).eq(i).hide();
						}
					} else {
						if( i > 0 ) {
							$(container).eq(i).hide();
						}
					}
				}
				// Loop through the buttons.
				for(var i = 0; i < $(button).length; i += 1) {
					var href = ( $(button).eq(i).prop('href') ).split('#'),
						id = href[1];
					if( Cookie.get('active_link') ) {
						if( id === (Cookie.get('active_link')) ){
							$(button).eq(i).parent('li').addClass('active');
						}
					} else {
						if( i < 1 ) {
							$(button).eq(i).parent('li').addClass('active');
						}
					}
				}
			},
			activate_link: function (){
				var self = this;
				$(button).click(function () {
					var href = ( $(this).prop('href') ).split('#'),
						id = href[1];
					if( Cookie.get('active_link') ){
						Cookie.erase('active_link');
						active_link = Cookie.set('active_link', id, 7);
					} else {
						active_link = Cookie.set('active_link', id, 7);
					}
					$(button).parent('li').removeClass('active');
					$(this).parent('li').addClass('active');
					self.toggle_container(id);
					return false;
				});
			},
			toggle_container: function (_id) {
				var self = this,
					id = _id || false,
					open = $(container + ':visible'),
					open_id = open.prop('id');
				if( id === false || open_id === id) {
					return false;
				}
				$(open).slideToggle();
				$('#' + id).slideToggle();
			},
			init: function () {
				this.style_nodes();
				this.activate_link();
			}
		}).init();
	};
	
var BackgroundImage = function (_config) {
		var config = _config || false;
		var img = (config.hasOwnProperty('image')) ? config.image : false,
			container = (config.hasOwnProperty('container')) ? config.container : '.image_append';
		if ( img === false ) {
			return false;
		}
		({
			add_image: function () {
				var img_node = $('<img>').load(function () {
						$(this).fadeIn();
					}).prop({
						src: img,
						id: 'page_image'
					}).hide();
				img_node.appendTo(container).bind( this.resize_image() );
			},
			resize_image: function () {
				var ratio = 12 / 8,
					bg_width = $(window).width(),
					bg_height = ( bg_width / ratio );
				if ( bg_height < $(window).height() ) {
					bg_height = $(window).height();
					bg_width = ( bg_height * ratio );
				}
				$('#page_image').css({
					'width': bg_width,
					'height': bg_height
				});
			},
			resize_window: function () {
				var self = this;
				$(window).resize(function () {
					self.resize_image();
				});
			},
			init: function (){
				this.add_image();
				this.resize_window();
			}
		}).init();
	};
	
var SlidingDoors = function (_config) {
		var config = _config || false;
		var container = ( config.hasOwnProperty('container') ) ? config.container : '.sliding_doors',
			slide = ( config.hasOwnProperty('slide') ) ? config.slides : '.slide',
			slides = $(container).find(slide),
			queuing = {
				queue: false
			};
		({
			container_width: ( $(container).width() ),
			slide_width: ( slides.width() ),
			slide_count: ( slides.length ),
			contract: function () {
				var i = ( this.container_width - ( this.slide_width ) ) / ( this.slide_count - 1 );
				return i;
			},
			style_nodes: function () {
				var self = this;
				$(container).children('ul').css({
					'width': ( self.slide_width * self.slide_count )
				});
				slides.css({
					'width': ( self.container_width / self.slide_count )
				});
			},
			slide_hover: function () {
				var self = this;
				slides.hover(function () {
					$(this).addClass('hover');
					self.slide_open();
				}, function () {
					self.slide_close();
					$(this).removeClass('hover');
				});
			},
			slide_open: function () {
				var self = this;
				slides.each(function () {
					if($(this).hasClass("hover")){
						$(this).animate({
							"width": self.slide_width
						}, queuing);
					} else {
						$(this).animate({
							"width": self.contract()
						}, queuing);
					}
				});
			},
			slide_close: function () {
				var self = this;
				slides.animate({
					"width": ( self.container_width / self.slide_count )
				}, queuing);
			},
			init: function () {
				this.style_nodes();
				this.slide_hover();
			}
		}).init();
	};
	
var Map = function (imgLocal, lat, long) {
    var myOptions = {
        zoom: 10,
        center: new google.maps.LatLng(lat, long),
        mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    var map = new google.maps.Map(document.getElementById("map_holder"), myOptions);
    var image = imgLocal;
    var myLatLng = new google.maps.LatLng(lat, long);
    var beachMarker = new google.maps.Marker({
        position: myLatLng,
        map: map,
        icon: image
    });
};

/*var DisableContextMenu = (function(){
		$(document).bind("contextmenu",function(e){
			return false;
		});
	})();*/


