/********************************************
 *
 *   Copyright 2010, Dokodemo Design
 *   www.dokodemodesign.com
 *	 Javascript Jquery document for Blog functions
 *   Authors: Justin Wright
 *   Source code: 'http://dokodemodesign.com/includes/test.inc.php';
 *******************************************/

function projectSlider(element, url, action, pos, space, width, height) {
$(element).click(function(e) {  
         //Cancel the link behavior  
         e.preventDefault(); 
		 $.simplemodal.modalMinHeight = height //'600px';
		 $.simplemodal.modalWidth = width; //'940px';
		 $.simplemodal.loaderWidth = width; //'940px';
		 $.simplemodal.loaderMinHeight = height //'600px';
		 $.simplemodal.modalBgColor = '#263033';
		 $.simplemodal.verticalOffset = 0;
		 $.simplemodal.ajaxData = action;
		 $.simplemodal.modalPos = pos; //'fixed';
		 
		 //slider param
		 $.simpleslider.spacing = space;
		 $.simpleslider.sliderHght = height;
		 
		 var $url = url;
		 var $close = '.closemodal';
		 var $loader = '<img src="http://dokodemodesign.com/images/ajaxBig-loader.gif" />';
		 jsimplemodal($url, $close, $loader, function() {  
				var $next = $('a.next').css('opacity', 0.8);
				var $prev = $('a.prev').css('opacity', 0.8);
				//set up jsimpleslider for all sliders
				jsimpleslider($next, $prev);
				$next.hover (function() { $(this).animate({opacity: 1}, 'slow'); },
				function() { $(this).animate({opacity: 0}, 'slow'); }  );
				$prev.hover (function() { $(this).animate({opacity: 1}, 'slow'); },
				function() { $(this).animate({opacity: 0}, 'slow'); }  );
				
				
					
		 });
		
	});
	} //close projectSlider

 
$(document).ready(function() {
//Document vars and hide actions
var $comments = $('a.viewcomments');
var $replies = $('a.viewreplies');
var $arrow = $('a.arrow');
$(".comments,ul.months, ul.days, .viewless, .commentsection, .replies").hide(); 


	
	//Show comments for blog posting
	$comments.click(function() {
	
	$(this).parents('div:first').find("div.comments").slideToggle("slow");
	var $link = $(this);
	
		if ( $link.text() == 'view comments' ) {
		$link.text('hide comments'); } else {
		$link.text('view comments');
		}
	
	}); //close click function
		//Show comments for blog posting
	$replies.click(function() {
	
	$(this).parents('div:eq(1)').find("div.replies").slideToggle("slow");
	//$(this).parents('div:eq(1)').addClass("joecool");
	var $link = $(this); 
		if ( $link.text() == "view replies" ) {
		$link.text('hide replies'); } else {
		$link.text('view replies');
		}
	
	}); //close click function
	
	
	//show first set of comments
	$('.show-section').each(function(index) { $(this).show(); });
	//revel more comments
	$('a[name=viewmore]').click(function(e){
		//Cancel the link behavior
		e.preventDefault();
		//get to the comment div and then search for the next comment section that does not have the show-section
		//add the show section and then show it
		$(this).parents('div:first').find("span.commentsection:not(.show-section)").first()
		.addClass('show-section').slideDown('slow');
		//show the viewless btn
		$(this).parent().nextAll('.viewless').show();
		
		
		//check how many elements have show-section within the great-grandparent element
		var elements = $(this).parents('div:first').find("span.show-section");
		var compareElements = $(this).parents('div:first').find("span.commentsection");
		//check if there are no more comments hidden
		if(elements.length == compareElements.length) { $(this).css({opacity: '0.5', cursor: 'text', color: '#3a7d75'})
		.bind('mouseover', function () { $(this).css('color', '#3a7d75'); });
 	}//close click function
		
		
	});//close show-section
	
	
	//viewless when click toggle up last comment section that has show-section
	$('a[name=viewless]').click(function(e) {
		//remove class and slid up
		$(this).parents('div:first').find("span.show-section").last()
		.removeClass('show-section').slideUp('slow');
		//check how many elements have show-section within the great-grandparent element
		var elements = $(this).parents('div:first').find("span.show-section");
		var compareElements = $(this).parents('div:first').find("span.commentsection");
		//alert(elements.length);//You get your Div number here;)
		if(elements.length == 1) { $(this).parents('div:first').find('.viewless').hide();}
		
		//alert(elements.length);//You get your Div number here;)
		if(elements.length != compareElements.length) { $(this).parents('div:first').find('a[name=viewmore]')
		.css({opacity: '1', cursor: 'pointer'}).bind('mouseover', function () { $(this).css('color', '#263033'); })
		.bind('mouseout', function () { $(this).css('color', '#3a7d75'); }); }
		

	});//close click function
	
	
	
	//move arrow up and down and revel dates of blog postings
	$arrow.click(function(e) {
	//Cancel the link behavior   
    e.preventDefault();	
		if($(this).is('.up')){
		$(this).css('background-position', '0 -20px').removeClass('up').addClass('down')
		.parent().next('ul').show();
		}else{
		$(this).css('background-position', '0 0').removeClass('down').addClass('up')
		.parent().next('ul').hide();
		}
	});//close arrow click fumction
	
	
	//load modal for posting comment
	
	
	//load projectSlider modals
	projectSlider('a[name=mayuphotoslider]', 'http://dokodemodesign.com/includes/slider.inc.php', 'action=mayuphoto', 'fixed',
					 920, '940px', '600px'); 
	//muops
	projectSlider('a[name=muops]', 'http://dokodemodesign.com/includes/slider.inc.php', 'action=muops','fixed', 
					 920,'940px', '600px'); 
	//katakana
	projectSlider('a[name=katakana]', 'http://dokodemodesign.com/includes/slider.inc.php', 'action=katakana','fixed', 
					 920,'940px', '600px'); 
	//iTunes
	projectSlider('a[name=ituneseasy]', 'http://dokodemodesign.com/includes/slider.inc.php', 'action=ituneseasy','absolute', 
					 632,'632px', '792px'); 

	
	
});  
