$(document).ready(function(){
//contains all the JS for the ub main site
$('#loadflash').click(function(e){
//console.log('click');
e.preventDefault();
if(screen.width <=768){ 
    window.location = 'http://www.ubaltmagazine.com/tour/'; 
} else{ 
    var head= document.getElementsByTagName('head')[0]; 
    var script= document.createElement('script'); 
    script.type= 'text/javascript';
    script.src='http://www.ubaltmagazine.com/tour/application/js/loadtour.js'; 
    head.appendChild(script);
}//endelse
});

$('.social1 li').hover(
		function(event){
			var cls = $(event.target).find('a').text();
			$("#social_desc p." + cls).show();
			
		},
		function(event){
			var cls = $(event.target).find('a').text();
			$("#social_desc p." + cls).hide();
		}
		);
		
	// social modal window
	$('.facebook2,.twitter2,.youtube2,.flickr2').hide();
	$('.social1 li').click(function(){
		$('#drop_social2').show();
		if( $(this).hasClass('twitter1') )	{
			$('.twitter2').show();
			$('.social2 li.twitter1').addClass('selected');
		}
		if( $(this).hasClass('facebook1') )	{
			$('.facebook2').show();
			$('.social2 li.facebook1').addClass('selected');
		}
		if( $(this).hasClass('youtube1') )	{
			$('.youtube2').show();
			$('.social2 li.youtube1').addClass('selected');
		}
		if( $(this).hasClass('flickr1') )	{
			$('.flickr2').show();
			$('.social2 li.flickr1').addClass('selected');
		}
	});

	$('.modal1').each(function(){
		body_height = ( (document.body.scrollHeight > document.body.offsetHeight) ? document.body.scrollHeight : document.body.offsetHeight);
		$(this).height(body_height);
		
	});
	
	
	// stop anchor click from causing problems
	$('.modal_close1,.modal_up1,.modal_down1').click(function(ev){
		ev.preventDefault();
	});
	
	$('.modal_close1,.modal_up1,.modal_down1').hover(function() {
		$(this).addClass('hover');
	}, function() {
		$(this).removeClass('hover');
	});
	$('.modal_close1').click(function(){
		$('#drop_social2,.facebook2,.twitter2,.youtube2,.flickr2').hide();
		$('.social2 li').removeClass('selected');
	});

	
	//scroll_position = $('.social_content1').offset().top;
	scroll_position = 0;
	scroll_amount = 200;
	max_scroll = 393;
	
	$('.modal_up1').click(function(){
		if(scroll_position > max_scroll)		{ scroll_position = max_scroll; }
		scroll_position = (scroll_position - (scroll_amount));
		$('.social_content1').animate({scrollTop:scroll_position}, 'slow');
	});
	$('.modal_down1').click(function(){
		if(scroll_position < 0)		{ scroll_position=0; }
		scroll_position = (scroll_position + scroll_amount);
		$('.social_content1').animate({scrollTop:scroll_position}, 'slow');
	});
	$('.social_content1').scroll(function(){
		scroll_position = $('.social_content1').scrollTop();
	});
	
	$('.social2 li').click(function(){
		$('.twitter2,.facebook2,.flickr2,.youtube2').hide();
		$('.social2 li').removeClass('selected');
		$(this).addClass('selected');
		if( $(this).hasClass('twitter1') )	{
			$('.twitter2').show();
		}
		if( $(this).hasClass('facebook1') )	{
			$('.facebook2').show();
		}
		if( $(this).hasClass('youtube1') )	{
			$('.youtube2').show();
		}
		if( $(this).hasClass('flickr1') )	{
			$('.flickr2').show();
		}
	});
	
	// off-click close modal
	$('#drop_social2').click(function(){
		$('#drop_social2,.facebook2,.twitter2,.youtube2,.flickr2').hide();
		$('.social2 li').removeClass('selected');
	});
	$('#drop_social2 .dropdown3').click(function(event){
		event.stopPropagation();
	});
	
	
	
});

