
/* Global Variables */
var BASEURL, ADMINUR, COREURL, SITEURL, MEDIAURL, THEMEURL, THE_URL;

var timeouts = [];
var videoPlaying = false;
function init_site(){
	clearClick();
	//setBrowserClass();
	search_focus();
	
	// Global Navigation of the site
	$("#nav > li").mouseenter(function() {
		$(this).addClass('amhover');
		if( $(this).children('ul').length >= 1) {
			var title = $(this).children('a').html();
			$(this).append('<div id="nav_title">'+title+'</div>');
		}
				
	}).mouseleave(function() {
		$(this).removeClass('amhover');
		$('#nav_title').remove();
	});
	
	// Find class with quote and add inqutoe to it.
	$('.sideQuote').wrapInner('<span class="inquote" />');
	// Find class with quote and add inqutoe to it.
	$('.mainQuote').wrapInner('<span class="inquote" />');
	
	// Find ol inside #text div and wrap the text with a span.
	$('#text ol li').wrapInner('<span class="" />');
	
	// Home page gallery
	
	if($('#gallery_wrapper .flexslider').length != 0) {
		
		// show the play button on links with videos
		$(".homegallerylinks").mouseenter(function(){
			if($(this).attr('href').match(/media/g)) {
				$(this).append('<div id="playbutton"></div>');
			}			
		}).mouseleave(function(){
			if($(this).attr('href').match(/media/g)) {
				$('#playbutton').remove();
			}			
		});
		// click function to either show the fancy box or link to the url assigned in the linklist
		$('.homegallerylinks').click(function() {
			
			if($(this).attr('href').match(/media/g)) {
				var mediaurl = $(this).attr('href');
				var params = {};
				params = {'mediaurl':mediaurl};
				$.ajax({
					type	: "POST",
					cache	: false,
					url		: THEMEURL + "/video.php",
					data		: params,
					success: function(data) {
						$.fancybox(
						data,
							{
							'autoDimensions'	: false,
							'width'         		: 576,
							'height'        		: 328,
							'transitionIn'	: 'elastic',
							'transitionOut'	: 'elastic',
							'onStart'			: toggle_slideshow,
							'onClosed'			: toggle_slideshow
							}
						);
					}
				});				
				
				return false;	
			}
		});
	}
	
}

// triggers the play pause on flexslider gallery
function toggle_slideshow() {
		$('.flex-pauseplay span').trigger('click');
	}

$(window).scroll(function () {
	smenu();
});

function smenu() {
	var menuPosition = 280;
	var scrollAmount=$(document).scrollTop();
	var newPosition = menuPosition+scrollAmount;
	$("#social_media").stop().delay(100).animate({top: newPosition}, 700, 'easeOutQuint');
}

function css_tweaks(){
	
}

// Opens a new window in the middle on the browser
function openNewWindow(theURL, winName, winWidth, winHeight){
	var width;
	var height;
	var leftdist;
	var topdist;
	width = screen.width;
	height = screen.height;
	leftdist = Math.round((width - winWidth) / 2);
	topdist = Math.round((height - winHeight) / 2);
	window.open(theURL, winName,'width='+winWidth+',height='+winHeight+',top='+topdist+',left='+leftdist+',noresize,resize=0,menubar=0,location=0,scrollbars=0')
	}

function search_focus() {
	$('#search_button').click(function(event) {
		if($('#search').hasClass('inputhide')) {
			event.preventDefault();
			$('#search').focus();	
		}
	});
}
