//alert('hello classic browser');
var open = false;

function getDocumentHeight() {  

	return document.documentElement.clientHeight;

}  
  
  
$(document).ready(function() {
						   
	
	$("a[rel^='prettyPhoto']").prettyPhoto({
					//animationSpeed: 'normal', /* fast/slow/normal */
					//padding: 40, /* padding for each side of the picture */
					//opacity: 0.35, /* Value betwee 0 and 1 */
					//showTitle: true, /* true/false */
					//allowresize: true, /* true/false */
					//counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
					theme: 'dark_square', /* light_rounded / dark_rounded / light_square / dark_square */
					hideflash: false /* 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 */
					//changepicturecallback: function(){}, /* Called everytime an item is shown/changed */
					//callback: function(){} /* Called when prettyPhoto is closed */
	});
						   
						   
	$("div#slider_tab").click(function () { 
		//alert('hello');
		if(open){
			$('div#slider_content').animate({width: 0}, 700);
			open = false;
		
		}
		else {
			$('div#slider_content').animate({width: 746}, 700);
			open = true;
		}
	});

	
	// OPEN HOVER PICS
	$('a.hoverpic').click(function () {
		//alert('asdf');
		var docHeight = getDocumentHeight();
		
		var newPic = $(this).attr('rel');
		
		var type = $(this).attr('alt');
		
		$('div#hover_pics').fadeIn('fast')
		
		if(type == 'p'){
			$('div#hover_pics').find('img').attr('src', newPic).show();
			$('div#hover_pics').find('iframe').hide();
			var imgH = $('div#hover_pics img').height();

		}
		else if(type == 'v') {
			$('div#hover_pics').find('img').hide();
			$('div#hover_pics').find('iframe').show();
			var imgH = $('div#hover_pics iframe').height();
		}
		
		
		
		//alert(docHeight);
		var newMargin = (docHeight/2)-(imgH/2);
		newMargin = Math.round(newMargin) + 'px';
		$('div#hover_pics .pic').css('margin-top', newMargin);
		
		return false;
	});
	
	// CLOSE HOVER PICS
	$("div#hover_pics .close").click(function () {
	
		$('div#hover_pics').fadeOut('fast');
												  
	});
	
	
	// MAXIMIZE HEIGHT
	var maxheight = 0;
	$('div.column_third').each(function(i){
	
									 
		var thisheight = $(this).height();
		if(thisheight > maxheight){
				maxheight = thisheight;	
		}
		//alert(maxheight);
		//$('div.column_third').height(maxheight);
		//thisul.find('li a').css('marginTop', '150px'};
	}).height(maxheight);
		
		
	// EMAILER
	$('div#emailer').hide();
	
	// remove original bgs for fields
	$('.remove_bg').focus(function(){
		$(this).css("background-image", "none");	   
	});
	
	$('input#emailis').blur(function(){
		var inputval = $(this).val();
		if(inputval.length < 1){
			$('input#emailis').css('background-image', 'url(assets/img/your_email_bg.png)');
		}
	});
	
	$('input#friendis').blur(function(){
	
		var inputval = $(this).val();
		if(inputval.length < 1){
			$('input#friendis').css('background-image', 'url(assets/img/friends_email_bg.png)');
		}
	});
	
	$('textarea#messageis').blur(function(){
	
		var inputval = $(this).val();
		if(inputval.length < 1){
			$('textarea#messageis').css('background-image', 'url(assets/img/message_bg.png)');
		}
	});
	
	
	
	
	
	

	$('a#close_emailer').click(function () {
		$('div#emailer').slideUp('fast');
		return false;
	});
	$('a#share3').click(function () {				
		$('div#emailer h5').css('background', 'url(assets/img/emailer_send.png)');
		$('input#emailis').css('background-image', 'url(assets/img/your_email_bg.png)');
		$('input#friendis').css('background-image', 'url(assets/img/friends_email_bg.png)');
		$('textarea#messageis').css('background-image', 'url(assets/img/message_bg.png)');
		$('div#emailer_form_wrapper').show('fast');
		$('#emailer_form')[0].reset();
		$('div#emailer').slideDown('fast');
		return false;
	});
	
	// disabled form
	// Disable the form submission
	$('form').submit(function()
	  {
		//alert('This is only a test.');
		var emailis    = $('input#emailis').val();
		var friendis   = $('input#friendis').val();
		var messageis = $('textarea#messageis').val();
		
		
		$.ajax({
			type: "POST",
			url: 'process_emailer.php', 
			data: "e="+emailis+"&f="+friendis+"&m="+messageis,
			success: function(msg) {
				//alert(msg);
				$('div#emailer h5').css('background', 'url(assets/img/emailer_sent.png)');
				$('div#emailer_form_wrapper').hide();
				$('div#emailer').fadeOut(5000);
			}			
		
		}); // ajax
		
		
		return false;
	  }
	);
	
	// fix safari 
	$('ul#share li a').html('&nbsp;');
	$('div.right h6').html('&nbsp;');
	
	
	
	
	
	
	
	
	
	
	// SCROLL COLUMNS
	
//	$('div.wrap_ul ul').hide('slow');
	$('div.wrap_ul ul').css('position', 'relative');
	//$('div.wrap_ul ul').animate({ 'top': '-100' } , 'slow');
	var ul_height = 420;
	
	$('a.nav_up').click(function () {
		
		var count = $(this).next('div.wrap_ul').attr('rel');
		var count_lis = 0;
		$(this).next('div.wrap_ul').find('ul').find('li').each(function(i) {
				count_lis++;
		});		

		var groups = Math.ceil(count_lis/5);
		
		//alert(groups);
		count--;
		if(count <= 0){
			count = 1;
			//alert(count);
		}
		
		var top = '-'+((ul_height*count)-ul_height);
		$(this).next('div.wrap_ul').find('ul').animate({ 'top': top } , 1000);
		$(this).next('div.wrap_ul').attr('rel', count);
		return false;
	
	});
	
	$('a.nav_down').click(function () {
		
		var count = $(this).parent().find('div.wrap_ul').attr('rel');
		var count_lis = 0;
		$(this).parent().find('div.wrap_ul').find('ul').find('li').each(function(i) {
				count_lis++;
		});		

		var groups = Math.ceil(count_lis/5);
		
		//alert(groups);
		count++;
		
		if(count > groups){
			count = 1;
			//alert(count);
		}

		var top = '-'+((ul_height*count)-ul_height);
		//alert(top);
		$(this).parent().find('div.wrap_ul').find('ul').animate({ 'top': top } , 1000);
		$(this).parent().find('div.wrap_ul').attr('rel', count);
		return false;
		
	});







	
	
	
// SCROLL COMPLICATORS
	
	function get_html() {
		//alert(comp_count);	
		var comp_count_minus = comp_count+1;
		var which = "ul#complicators_ul li:nth-child("+comp_count_minus+")";
		var href = $(which).find('a').attr('href');
		//alert(which);
		//alert(href);
		$('a#comp_facebook').attr('href', href);
	}

	get_html();
	
	var comp_w = 262;
	var comp_count = 0;
	var comp_total = 7;
	
	$('ul#complicators_ul').css('position', 'relative');
	//$('ul#complicators_ul').animate({ 'left': '-100' } , 'slow');

	$('a#comp_left').click(function () {
		if(comp_count <= 0){ comp_count = comp_total; }
		comp_count--;
		var left = '-'+(comp_count*comp_w);
		$('ul#complicators_ul').animate({ 'left': left } , 'fast');
		
		get_html();
		
		return false;
	});
	
	$('a#comp_right').click(function () {
		if(comp_count >= (comp_total-1)){ comp_count = -1; }
		comp_count++;
		var left = '-'+(comp_count*comp_w);
		$('ul#complicators_ul').animate({ 'left': left } , 'fast');
		
		get_html();
		
		return false;
	});

	
	
	
});