$(document).ready(function(){
	
	max_height = 0;
	$('.section').each(function(){
		max_height = Math.max($(this).height(), max_height);
	});
	//$('.section').css('height', max_height + "20");
	
	// If the mailing list module is loaded on the page, enable the submit button
	$('a#mailinglist_submit').click(function(){ mailinglist_subscribe(); return false; });
	
	// max_height = 0;
	// $('body#products .section').each(function(){
	// 	max_height = Math.max($(this).height(), max_height);
	// });
	// $('body#products #section_wrapper').css('height', max_height);
	
	$('body#products #tabs ul li a').click(function(){
		id = $(this).attr('id').replace('nav_', '');

		$('#products #tabs ul li a div').removeClass('link_active');
		$('#products #tabs ul li a#nav_'+id+' div').addClass('link_active');
		


		// $('.section').fadeOut("fast", function(){
		// 	if($(this).attr('id') == "section_downloads"){
		// 		$('#section_'+id).fadeIn("fast");
		// 	}
		// 	
		// });
		$('.section').hide();
		$('#section_'+id).fadeIn("fast");
		
		
		return false;
	})
	$('body#products #section_overview').fadeIn("fast");
	

});

function openShadowbox(content, player, title){
    Shadowbox.open({
        content:    content,
        player:     player,
        title:      title
    });
}


function open_gallery(gallery_id){
	
	$.getJSON("../../gallery.php?id="+gallery_id,
	        function(data){
		
				var options = {
			        continuous: true
			    };
			   
				var images = [];
				j = data.images.length
				for (var i=0; i < j; i++) {
					images.push({ 
						player:     data.images[i].display_type,
				        content:    data.images[i].filename,
				        height:     data.images[i].height,
				        width:      data.images[i].width,
				        options:    options,
				  		title:     data.images[i].title
				    });
				};
	
	      		Shadowbox.open(images);
	        });

}

function changeLanguage(newLanguage){
	
		// Get the current URL
		sURLFull = window.location.href.split("?");
	
		// Grab the script path.
		sURL = sURLFull[0]+'?language='+newLanguage;
	
		// If there was a query string attached to the current page load...
		if(sURLFull.length > 1 && sURLFull[1].length>0){
			// ... replace any language setting and add it to the new URL.
			sURL += "&" + sURLFull[1].replace('language','old');
		}
		
	// Reload the window with the new language.
	window.location.href = sURL;
}

function mailinglist_subscribe(){
	email = $('input#mailinglist_email').val();
	name =  $('input#mailinglist_name').val();
	
	data = {};

	
	data.email = $('input#mailinglist_email').val();
	data.name = $('input#mailinglist_name').val();
	
	$(".mailinglist_custom input:selected").each(function(i){
		console.log($(this).attr('id') + " :: " + $(this).val());
	});
	
	$(".mailinglist_custom input:checked").each(function(i){
		input_name = $(this).attr('name');
		input_value =  $(this).val();
		
		if(data[input_name] == undefined){
			data[input_name] = input_value;		
		} else {
			data[input_name] += ","+input_value;
		}

	});

	$(".mailinglist_custom input:text").each(function(i){
		if(data[input_name] == undefined){
			data[input_name] = input_value;		
		} else {
			data[input_name] += ","+input_value;
		}
	});
	
	$.post(site_url+"/"+language+"/ajax/mailinglist/", 
			data,
	   		function(data){	
			     console.log(data); //  2pm
			});	
			
	
}

	function triggerLink(iID){
		
			window.location.href = links[iID];
		
	}