                                                                                                                                                                                                                                // JavaScript Document


// Gallery Pagination



var pageSize = 15; // number of images displayed on page
var imagesParent = ".galleryImgItem li"; // HTML container where the the image are found
var nextButton = "#nextBtn"; // class or id of the Next button
var previousButton = "#preBtn"; // class or id of the Previous button
var paginationNumberContainer = ".galPaginate"; // container for page numbers
var pageNumberAnchor = true; // this will create page number links inside "paginationNumberContainer" element. false will turn the function off



var numberOfImages = $(imagesParent).length; 

function dispPage(pageNum){	
try{
	var listItems = $(imagesParent);
	var pageMax = Math.ceil($(imagesParent).length / pageSize);
	
	
	// checks for images
	if(listItems.length > 0){
		$(listItems).hide();
		for(i=((pageSize*pageNum) - pageSize);i<pageSize*pageNum; i++){
			   if(listItems[i]!=undefined)
					$(listItems[i]).show();  
		}
				
		
		// functions next and previous buttons
			$(nextButton).unbind().click(function(){  
				pageNum = parseFloat(pageNum);								
				dispPage(pageNum+1);
				return false;
			});
			
			$(previousButton).unbind().click(function(){
				pageNum = parseFloat(pageNum);	
				dispPage((pageNum)-1);
				return false;
			});
			
			
		
		// display of next and previous buttons
	 	if(pageNum == 1){
			$(previousButton).hide();
			$(nextButton).show();

		}else if(pageNum == pageMax){
			$(nextButton).hide();
			$(previousButton).show();
			
		}else{					
			$(previousButton).show();
			$(nextButton).show();
		}

	}else{ // if no images listed
		
		$(nextButton).hide();
		$(previousButton).hide();
	}


       $('.agreeContainer').hide();
       $('.agreeBtn').click(function(){
       $('.agreeContainer').slideToggle();
       $('.buyOff').slideToggle();
       $('.agreeBtn').toggleClass("agreeBtn-active");
       });

	
	// creating pagination numbers links
	if(!!pageNumberAnchor){
		for(x=1; x<pageMax+1;x++){
			$(paginationNumberContainer).append("<a href='javascript:;' rel='"+x+"'>"+x+"</a>");			
		}
		pageNumberAnchor = false;
	}	
	
	$(paginationNumberContainer+ " a").removeClass("pageSelect");
	$(paginationNumberContainer+ " a:eq("+(pageNum-1)+")").addClass("pageSelect");
        

	// pagination selected states and function
	$(paginationNumberContainer+ " a").unbind().click(function(){
				var pageNumberRel = $(this).attr('rel');
				var PageNumberRel = parseFloat(pageNumberRel);
				$(paginationNumberContainer+ " a").removeClass("pageSelect");
				
				dispPage(pageNumberRel);
				$(this).addClass("pageSelect");
				return false
				
		});

}catch(err){}
}



$(function(){

dispPage(1);

	// this will only show one date in the events box
	
	$(".event").each(function(){
		  $("h2:first" , this).show();
	});
	try{
		var s = $('#eventPhoto').attr('src').split("_resize");
		var t = s[1].split("."); 
		var size = t[0].split("x");
		var width = size[0];
		var height = size[1];
		
		var i = new Image();
		i.onload = function(){
		var ratio = i.width / i.height;
		
		if (ratio > 1)
		{
			width = 256;
			height = parseInt(256 / ratio); 
		}
		else
		{
			width = parseInt(256 * ratio); 
			height = 256; 
		}
		
		var newImg = s[0] + "_resize"+width + "x" + height + "." + t[1];		
		$('#eventPhoto').attr('src', newImg);
		};
		i.src = s[0] + "." + t[1]; 
	}catch(err){}

	// select box to view with venues
	/*
	$("select#selVenue").change(function(){
			var selVal = $(this).val();
			// Above Code grabs the category field out of article topics to pull into the query 
			window.location = "/Pages/Events+List?venue="+selVal;
	});
	*/	
	
	// shorten description on blog page
	
	if($("#blogList").length >= 1){
		$('.cutDesc').each(function(){
			var newChar = $(this).html().substring(0,150);		
			$(this).html(newChar);
		});
	}



         // disable enter key on event page

       $(".skuQty").bind("keypress", function(e) {
        if (e.keyCode == 13) return false;
        });





});




if(window.location == "http://globaladrenaline.tecture.net/Pages/Media")
{
      $(document).ready(function() {
	$('.cutDesc').each(function() {
		var newChar = $(this).text().substring(0,150);
		
		$(this).text(newChar);

	});

      });
};


$(document).ready(function() {
	
	

	$('.blogCut').each(function() {
		var newChar = $(this).text().substring(0,150);
		$(this).text(newChar);
	});
	
	
	var venueShots = $('.intShot img.slideshow').length;
	//alert(venueShots);
	
	$('.intShot').hide();
	
	if($('.intShot img.slideshow').length > 0){
		$('.intShot').show();
	}
	
	// Event Hierarchy
	
	

	
});


// copy to clipboard



function SelectAll(id)
{
    document.getElementById(id).focus();
    document.getElementById(id).select();
}

function createPager(div, pageSize)
{	
	var count = div.children("a").size();
	var page = location.href.split("page=")
	page = page[1] ? page[1].split("&")[0] : 1;
	page = parseInt(page);
	var left = page;
	var right = page;
	var total = pageSize;

	while(left > page - pageSize && left > 1)
		left--;
		
	while(right < page + pageSize)
	{
		if (right == count)
			break;
		else
			right++;
	}
	
	var l = (page - left);
	var r = (right - page);
	
	if (l < r)
		r = pageSize - l;
	else if (l > r)
		l = pageSize - r;
	else
	{
		var total = pageSize - Math.floor(pageSize/2);
		r = Math.floor(pageSize/2);
		l = total;
	}
	
	left = page - l;
	right = page + r;
	var span = "<span class=\"dotBreak\">...</span>";
	
	div.children("a").each(function(i){
		if (i < left-1 || i > right-1)
			div.children("a:eq("+i+")").hide();
		if (left > 1 && i == left - 1)
			div.children("a:eq("+i+")").before(span);
		if (right < count && i == right - 1)
			div.children("a:eq("+i+")").after(span);
	});
	
	var first = div.children("a:first").attr("href");
	var last = div.children("a:last").attr("href");
	
	if (left > 1)
		div.children("a:first").before("<a href=\""+first+"\">First</a>");
	if (right < count)
		div.children("a:last").after("<a href=\""+last+"\">Last</a>");
}



    

    

    

    

    

    

    

    

    

    

    

    

    

    

    

    

    

    

    

    

    

    

    

    
