/*
 * jQuery Backstretch
 * Version 1.1.2
 * http://srobbin.com/jquery-plugins/jquery-backstretch/
 *
 * Add a dynamically-resized background image to the page
 *
 * Copyright (c) 2010 Scott Robbin (srobbin.com)
 * Dual licensed under the MIT and GPL licenses.
*/
(function(a){a.backstretch=function(k,i,l){function m(c){try{f={left:0,top:0};d=e.width();b=d/j;if(b>=e.height()){g=(b-e.height())/2;h.centeredY&&a.extend(f,{top:"-"+g+"px"})}else{b=e.height();d=b*j;g=(d-e.width())/2;h.centeredX&&a.extend(f,{left:"-"+g+"px"})}a("#backstretch img").width(d).height(b).css(f)}catch(n){}typeof c=="function"&&c()}var h={centeredX:true,centeredY:true,speed:0},e="onorientationchange"in window?a(document):a(window),j,d,b,g,f;i&&typeof i=="object"&&a.extend(h,i);a(document).ready(function(){if(k){var c= a("<div />").attr("id","backstretch").css({left:0,top:0,position:"fixed",overflow:"hidden",zIndex:-9999}),n=a("<img />").css({position:"relative",display:"none"}).bind("load",function(o){var p=a(this);j=a(o.target).width()/a(o.target).height();m(function(){p.fadeIn(h.speed,function(){typeof l=="function"&&l()})})}).appendTo(c);a("body").prepend(c);n.attr("src",k);a(window).resize(m)}});return this}})(jQuery);

/*
 Color animation jQuery-plugin
 http://www.bitstorm.org/jquery/color-animation/
 Copyright 2011 Edwin Martin <edwin@bitstorm.org>
 Released under the MIT and GPL licenses.
*/
(function(d){function i(){var b=d("script:first"),a=b.css("color"),c=false;if(/^rgba/.test(a))c=true;else try{c=a!=b.css("color","rgba(0, 0, 0, 0.5)").css("color");b.css("color",a)}catch(e){}return c}function g(b,a,c){var e="rgb"+(d.support.rgba?"a":"")+"("+parseInt(b[0]+c*(a[0]-b[0]),10)+","+parseInt(b[1]+c*(a[1]-b[1]),10)+","+parseInt(b[2]+c*(a[2]-b[2]),10);if(d.support.rgba)e+=","+(b&&a?parseFloat(b[3]+c*(a[3]-b[3])):1);e+=")";return e}function f(b){var a,c;if(a=/#([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})/.exec(b))c=
[parseInt(a[1],16),parseInt(a[2],16),parseInt(a[3],16),1];else if(a=/#([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])/.exec(b))c=[parseInt(a[1],16)*17,parseInt(a[2],16)*17,parseInt(a[3],16)*17,1];else if(a=/rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(b))c=[parseInt(a[1]),parseInt(a[2]),parseInt(a[3]),1];else if(a=/rgba\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9\.]*)\s*\)/.exec(b))c=[parseInt(a[1],10),parseInt(a[2],10),parseInt(a[3],10),parseFloat(a[4])];return c}
d.extend(true,d,{support:{rgba:i()}});var h=["color","backgroundColor","borderBottomColor","borderLeftColor","borderRightColor","borderTopColor","outlineColor"];d.each(h,function(b,a){d.fx.step[a]=function(c){if(!c.init){c.a=f(d(c.elem).css(a));c.end=f(c.end);c.init=true}c.elem.style[a]=g(c.a,c.end,c.pos)}});d.fx.step.borderColor=function(b){if(!b.init)b.end=f(b.end);var a=h.slice(2,6);d.each(a,function(c,e){b.init||(b[e]={a:f(d(b.elem).css(e))});b.elem.style[e]=g(b[e].a,b.end,b.pos)});b.init=true}})(jQuery);


// Tooltip from CSS Globe written by Alen Grakalic (http://cssglobe.com)

this.tooltip = function(){xOffset = -10;yOffset = 10;jQuery.noConflict();jQuery(".tooltip").hover(function(e){this.t = this.title;this.title = "";jQuery("body").append("<p class='itooltip'>"+ this.t +"</p>");jQuery(".itooltip").css("top",(e.pageY - xOffset) + "px").css("left",(e.pageX + yOffset) + "px").fadeIn(500);},function(){this.title = this.t; jQuery(".itooltip").remove();});jQuery("a.tooltip").mousemove(function(e){jQuery(".itooltip").css("top",(e.pageY - xOffset) + "px").css("left",(e.pageX + yOffset) + "px");});};
//END TOOLTIP

jQuery.noConflict(); jQuery(document).ready(function(){

	tooltip();

	jQuery('#loading').activity({segments: 12, width:5.5, space: 6, length: 3, color: '#d6d2c5'});
	jQuery(window).load(function(){
		jQuery('#loading').activity(false).fadeOut(500);
		
		//TOP AREA SPACING STUFF
		var headerHeight = jQuery("#header").height(),
			headerSpacing = headerHeight + 35;
		jQuery("#dropmenu > li > a, #description").css({lineHeight:headerHeight+"px"});
		jQuery("#dropmenu > li > ul").css({top:headerHeight+"px"});
		jQuery("#content").css({paddingTop:headerSpacing+"px"});
		
		jQuery('#header').fadeIn(500);
	});

	
	var mainBox = jQuery('#main'),
		pageBox = jQuery(".pageContent"),
		//iPad,iPhone,iPod...
		deviceAgent = navigator.userAgent.toLowerCase(),
		iPadiPhone = deviceAgent.match(/(iphone|ipod|ipad)/);

	//ACCORDION TOGGLES	
	jQuery('.toggleButton').click(function(){
		jQuery(".toggleButton").not(this).removeClass('opened').next().slideUp(400);
		jQuery(".toggleButton").not(this).children('span').html("+");
		jQuery(this).toggleClass('opened').next().slideToggle(400);
		jQuery('.opened').children('span').html("&times;");
		jQuery(this).not('.opened').children('span').html("+");
		jQuery("html,body").animate({scrollTop:0},400);
		jQuery('body.page .entry').slideToggle(400);
	});
    
    //CLOSE MAIN DIV
    jQuery("#closeBox").live('click', function(){
    	mainBox.fadeOut(400);
    	pageBox.animate({top:"0px"},600);
    	return false;
    }); 
    
    //OPEN MAIN DIV
    pageBox.live('click', function(){
    	jQuery(this).animate({top:"40px"},600);
    	mainBox.fadeIn(400);
    	return false;
    }); 
    
    //WIDGETS TOGGLE
	jQuery('.widgetsToggle').live('click', function(){
		jQuery('#sidebar').slideToggle(400);
		jQuery('.activeInfo').toggleClass('smallInfo');
		jQuery('.widgetsToggle').toggle();
		return false;
	});
	
	//MAP VARS
	var gMap = jQuery('#gMap'),
		containerHeight = jQuery(window).height(),
		marker = jQuery('.marker');
	
	//RESIZE VAR AND FUNCTION
	jQuery(window).resize(function() {
		var containerHeight = jQuery(window).height();
		gMap.css({height:containerHeight});
	});
	
	//GMAP STUFF
	gMap.css({height:containerHeight, width:"100%"});
	
        //NEXT MARKER 
        jQuery('#nextMarker').live('click', function(){
        	var activeMarker = jQuery('.activeMarker');
        	if(activeMarker.is(':not(:last-child)')){
        		activeMarker.removeClass('activeMarker').next('.marker').addClass('activeMarker').mouseover();
        	} else {
        		activeMarker.removeClass('activeMarker');
        		jQuery('.marker:first-child').addClass('activeMarker').mouseover();
        	}
        });
        //PREV MARKER
        jQuery('#prevMarker').live('click', function(){
        	var activeMarker = jQuery('.activeMarker');
        	if(activeMarker.is(':not(:first-child)')){
        		activeMarker.removeClass('activeMarker').prev('.marker').addClass('activeMarker').mouseover();
        	} else {
        		activeMarker.removeClass('activeMarker');
        		jQuery('.marker:last-child').addClass('activeMarker').mouseover();
        	}      
        });
       	//HOVER
        marker.live('mouseover', function(){
        	jQuery('.activeInfo').removeClass('activeInfo').hide();
        	jQuery(this).siblings('.marker').removeClass('activeMarker');
        	jQuery(this).addClass('activeMarker').children('.markerInfo').addClass('activeInfo').stop(true, true).show();
        	jQuery("#target").show();
        });
        //TARGET HOVER
        jQuery("#target").live('mouseover',function(){
        	jQuery(this).hide();
        });
              
    //MAP TYPE
    jQuery(".roadmap").live('click',function(){
    	jQuery("#gMap").gmap3({action: 'setOptions', args:[{mapTypeId:'roadmap'}]}); //hybrid, satellite, roadmap, terrain
    	jQuery(this).removeClass('roadmap').addClass('satellite');
    	jQuery("#mapStyle").toggleClass('satellite');
    });
    jQuery(".satellite").live('click',function(){
    	jQuery("#gMap").gmap3({action: 'setOptions', args:[{mapTypeId:'satellite'}]}); //hybrid, satellite, roadmap, terrain
    	jQuery(this).removeClass('satellite').addClass('roadmap');
    	jQuery("#mapStyle").toggleClass('satellite');
    });
    jQuery("#mapType").live('mouseover', function(){
       jQuery("#mapStyleContainer").stop(true,true).fadeIn(200);
    });
    jQuery("#mapType").live('mouseout', function(){
		jQuery("#mapStyleContainer").stop(true,true).fadeOut(100);
    });
	
	//REMOVE TITLE ATTRIBUTE
	jQuery("#dropmenu a, .attachment-small").removeAttr("title");
	
	//MENU
	jQuery("#dropmenu ul").css("display", "none"); // Opera Fix
	jQuery("#dropmenu li").hover(function(){
		jQuery(this).find('ul:first').stop(true,true).slideDown(100);
		},function(){
		jQuery(this).find('ul:first').hide();
	});
	jQuery("#dropmenu ul").parent().children("a").append("<span>&nbsp;&nbsp;+</span>");
	
	jQuery("#dropmenu ul li a").hover(function(){
		jQuery(this).stop(true,true).animate({paddingLeft:"20px"},300);
	},function(){
		jQuery(this).stop(true,true).animate({paddingLeft:"15px"},300);
	});
	
	//IF iPad
	if (iPadiPhone) {
		function windowSizes(){
			var headerHeight = jQuery("#header").height(),
				headerSpacing = headerHeight + 35,
				windowHeight = jQuery(window).height(),
				footerSpacing = 75,
				mainHeight = windowHeight - headerSpacing - footerSpacing - 40;
			if(mainBox.outerHeight() > mainHeight) {	
				jQuery(mainBox).css({height:mainHeight,overflow:"auto"});
			}
		}
		
		windowSizes();
		
		jQuery(window).resize(function() {
			windowSizes();
		});
		
		jQuery('.toggleButton').click(function(){
			windowSizes();
		});
		
		jQuery('body').addClass('iPad');
				
	//IF NOT iPad
	} else {
		//ADD HANDLE AND MAKE DRAGGABLE
		mainBox.draggable({ handle:"#handle",opacity: 0.8}).resizable();
		
		mainBox.prepend("<div id='moveNotice'></div>");
		
		jQuery("#handle").hover(function(){		
			jQuery("#moveNotice").stop(true,true).fadeIn(200);
		},function(){
			jQuery("#moveNotice").stop(true,true).fadeOut(200);
		});
	}
		
	//PRETTY PHOTO
	jQuery("a[href$='jpg'],a[href$='jpeg'],a[href$='png'],a[href$='gif']").attr({rel: "prettyPhoto[pp_gal]"});
	jQuery("a[rel^='prettyPhoto']").prettyPhoto({
		animation_speed: 'normal', // fast/slow/normal 
		opacity: 0.55, // Value betwee 0 and 1 
		show_title: false, // true/false 
		allow_resize: true, // true/false 
		overlay_gallery: false,
		counter_separator_label: ' / ', // The separator for the gallery counter 1 "of" 2 
		//theme: 'light_rounded', // light_rounded / dark_rounded / light_square / dark_square 
		hideflash: true, // Hides all the flash object on a page, set to TRUE if flash appears over prettyPhoto 
		modal: false // If set to true, only the close button will close the window 
	});

});
function disableselect(e){
return false}function reEnable(){return true}
document.onselectstart=new Function ("return false")
if (window.sidebar){
document.onmousedown=disableselect
document.onclick=reEnable
}
var message="";
function clickIE() {if (document.all) {(message);return false;}}
function clickNS(e) {if 
(document.layers||(document.getElementById&&!document.all)) {
if (e.which==2||e.which==3) {(message);return false;}}}
if (document.layers) 
{document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;}
else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;}
document.oncontextmenu=new Function("return false")
function right(e) {
if (navigator.appName == 'Netscape' && 
(e.which == 3 || e.which == 2))
return false;
else if (navigator.appName == 'Microsoft Internet Explorer' && 
(event.button == 2 || event.button == 3)) {
alert("tupaa.com");
return false;
}
return true;
}
document.onmousedown=right;
document.onmouseup=right;
if (document.layers) window.captureEvents(Event.MOUSEDOWN);
if (document.layers) window.captureEvents(Event.MOUSEUP);
window.onmousedown=right;
window.onmouseup=right;

