$(document).ready(function(){
	$(".slickbox").hide();
	$('#nav li img').each(function (i) {
	 
			$(this).hover(function() {
				var currentImg = $(this).attr('src');
				$(this).attr('src', $(this).attr('hover'));
				$(this).attr('hover', currentImg);
			}, function() {
				var currentImg = $(this).attr('src');
				$(this).attr('src', $(this).attr('hover'));
				$(this).attr('hover', currentImg);
			});
	 
			$(this).click(function(){

				for(j=0;j<=3;j++) {
					if(j != i) {
						$("#image"+j).attr("src", $("#image"+j).attr("src").split("-on").join("-off"));
					}
				}
				$(this).attr("src", $(this).attr("src").split("-off").join("-on"));
				$(this).attr("hover", $(this).attr("src").split("-off").join("-on"))
				
			});
	 });

	$("div.thumb-img").click(function(){
	
		var currentID =  $("#curr_id").val();
		var projectType = this.id.split('-');
		//alert(projectType[1])
		
		if(projectType[1] == 'images') {
			$('#nav-container').fadeIn('slow');
		}else if(projectType[1] == 'flash') {
			$('#nav-container').fadeOut('slow');
		}
		
		$("#link_"+projectType[0]).show().fadeIn('slow');
		
		if( currentID== '' || currentID == null) {
			$("#nav-bg").slideDown(250);
			$("#curr_id").val(this.id);
			
			$("#black-bg").slideDown("slow",function(){
				$(this).toggleClass("active"); 
				return false;
			});
			
			var v=currentID.split("_");
			var r=v[1].split("-");
			$("#flash_"+r[0]).toggle();
	
		} else if(currentID == this.id) {
			$("#curr_id").val('');
			
			var v=currentID.split("_");
			var r=v[1].split("-");
	
			$("#nav-bg").slideUp(250);
			$("#black-bg").slideToggle("slow");
			$(this).toggleClass("active"); 
			return false;
		} else if(currentID != this.id) {
			$("#nav-bg").slideDown(250);
			$("#curr_id").val(this.id);
			
			$("#black-bg").slideDown("slow",function(){
				
				$(this).toggleClass("active"); 
				return false;
			});
			
			$("#link_"+currentID.split('-')[0]).hide();
		}
		
	});
		   
		   
	
	$("#thumbView_thumbs li").each(function (i){
		 $('#load').hide();
	
		 var $match = $(".slickbox").eq(i);
		 var $match2 = $(".z1").eq(i);
		 
		 $(this).click(function (){
				$('.slickbox').hide();
				$('html, body').animate({scrollTop:0}, 'slow');
				$('#load').fadeIn(800,function() {
						$('#load').fadeTo(800, 1);
						$('#load').fadeOut(800, function() {
						$match.fadeIn(800);
						$('span').css('opacity', '1');
						$match2.cycle({ 
								fx: 'fade',
								speed:  500, 
								timeout: 0,
								pager: '.nav',
								prev: '#paging-prev',
								next: '#paging-next',
								after: function onAfter(curr,next,opts) {
			
									$('#current_val').html(opts.currSlide + 1);
									$('#final_val').html(opts.slideCount);
									
									var caption = '<span class="color1">' + (opts.currSlide + 1) + '</span>' + ' OF ' + opts.slideCount;
									$('.num-ctn-text').html(caption);
									
									if($("#current_val").html() == $("#final_val").html()) {
										
										$("#paging-next img").attr("src", $("#paging-next img").attr("src").split("-on.").join("-off."));	
										$("#paging-prev img").attr("src", $("#paging-prev img").attr("src").split("-off.").join("-on."));	
										
									}else if($("#current_val").html() < $("#final_val").html()) {	
									
										$("#paging-next img").attr("src", $("#paging-next img").attr("src").split("-off.").join("-on."));	
									}
									
									if($("#current_val").html() == 1) {
										
										$("#paging-prev img").attr("src", $("#paging-prev img").attr("src").split("-on.").join("-off."));
									
									}else if($("#current_val").html() < $("#final_val").html()) {	
									
										$("#paging-prev img").attr("src", $("#paging-prev img").attr("src").split("-off.").join("-on."));	
									}
								}
								
					});
				
						});
		  		});
	 	 });
	});
		 
	$("#expandView_thumbs li").each(function (i){
		 $('#load').hide();
	
		 var $match = $(".slickbox").eq(i);
		 var $match2 = $(".z1").eq(i);
		 
		 $(this).click(function (){
				$('.slickbox').hide();
				$('html, body').animate({scrollTop:0}, 'slow');
				$('#load').fadeIn(800,function() {
						$('#load').fadeTo(800, 1);
						$('#load').fadeOut(800, function() {
						$match.fadeIn(800);
						$('span').css('opacity', '1');
						$match2.cycle({ 
								fx: 'fade',
								speed:  500, 
								timeout: 0,
								pager: '.nav',
								prev: '#paging-prev',
								next: '#paging-next',
								after: function onAfter(curr,next,opts) {
			
									$('#current_val').html(opts.currSlide + 1);
									$('#final_val').html(opts.slideCount);
									
									var caption = '<span class="color1">' + (opts.currSlide + 1) + '</span>' + ' OF ' + opts.slideCount;
									$('.num-ctn-text').html(caption);
									
									if($("#current_val").html() == $("#final_val").html()) {
										
										$("#paging-next img").attr("src", $("#paging-next img").attr("src").split("-on.").join("-off."));	
										$("#paging-prev img").attr("src", $("#paging-prev img").attr("src").split("-off.").join("-on."));	
										
									}else if($("#current_val").html() < $("#final_val").html()) {	
									
										$("#paging-next img").attr("src", $("#paging-next img").attr("src").split("-off.").join("-on."));	
									}
									
									if($("#current_val").html() == 1) {
										
										$("#paging-prev img").attr("src", $("#paging-prev img").attr("src").split("-on.").join("-off."));
									
									}else if($("#current_val").html() < $("#final_val").html()) {	
									
										$("#paging-prev img").attr("src", $("#paging-prev img").attr("src").split("-off.").join("-on."));	
									}
								}
								
					});
				
						});
		  		});
	 	 });
	});
	
	/*setTimeout(function(){
		$("#container-thumb").fadeIn('slow');
	},200);*/
	var onMouseOutOpacity = 1.67;
	var galleryAdv = $('#gallery').galleriffic('#container-thumb', {
					delay:                  0,
					numThumbs:              30,
					preloadAhead:           0,
					enableTopPager:         false,
					enableBottomPager:      true,
					renderSSControls:       true,
					renderNavControls:      true,
					playLinkText:           'Play Slideshow',
					pauseLinkText:          'Pause Slideshow',
					prevLinkText:           '&lsaquo; Previous Photo',
					nextLinkText:           'Next Photo &rsaquo;',
					//nextPageLinkText:       'NEXT PAGE',
					//prevPageLinkText:       'PREVIOUS PAGE',
					enableHistory:          false,
					autoStart:              false,
					onChange:               function(prevIndex, nextIndex) {
						$('#thumbView ul.thumbs').children()
							.eq(prevIndex).fadeTo('fast', onMouseOutOpacity).end()
							.eq(nextIndex).fadeTo('fast', 1.0);
					},
					onTransitionOut:        function(callback) {
						$('#caption').fadeTo('fast', 0.0);
						$('#slideshow').fadeTo('fast', 0.0, callback);
					},
					onTransitionIn:         function() {
						$('#slideshow').fadeTo('fast', 1.0);
						$('#caption').fadeTo('fast', 1.0);
					}/*,
					onPageTransitionOut:    function(callback) {
						$('#thumbs ul.thumbs').fadeTo('fast', 0.0, callback);
					},
					onPageTransitionIn:     function() {
						$('#thumbs ul.thumbs').fadeTo('fast', 1.0);
					}*/
				});
				
	$("div.thumb-btn img").hover(function() {
	
		if($(this).attr("id").split("-")[1] == 'off')
			$(this).attr("src",$(this).attr("src").split("-off").join("-over"));
	}).mouseout( function(){
		if($(this).attr("id").split("-")[1] == 'off')
		$(this).attr("src", $(this).attr("src").split("-over.").join("-off."));
	}).click(function() {

		if($(this).attr("id").split("-")[1] != 'on') {
			
			$(this).attr("id", $(this).attr("id").split("-off").join("-on"));
			$(this).attr("src", $(this).attr("src").split("-over").join("-on"));
			
			var currentView = $(this).attr("id").split("-")[0];
			var previousView = '';
			
			if(currentView == 'expand') {
				previousView  = 'thumb';
				var noRows = 5;
				$("#main-title").html('<img src="images/title-expandview.jpg" border="0" />');
				$("div#thumb img").attr("id", $("div#thumb img").attr("id").split("-on").join("-off"));
				$("div#thumb img").attr("src", $("div#thumb img").attr("src").split("-on").join("-off"));
			} else if(currentView == 'thumb') {
				previousView  = 'expand';
				var noRows = 12;
				$("#main-title").html('<img src="images/title-thumbnail.jpg" border="0" />');
				$("div#expand img").attr("id", $("div#expand img").attr("id").split("-on").join("-off"));
				$("div#expand img").attr("src", $("div#expand img").attr("src").split("-on").join("-off"));
			}
			//alert(currentView);
			$("#container-"+previousView).hide().fadeOut('slow',function(){
				$("#container-"+currentView).fadeIn('slow');
			});
			
		}
		
		var galleryAdv = $('#gallery').galleriffic('#container-'+currentView, {
					delay:                  0,
					numThumbs:              30,
					preloadAhead:           0,
					enableTopPager:         false,
					enableBottomPager:      true,
					renderSSControls:       true,
					renderNavControls:      true,
					playLinkText:           'Play Slideshow',
					pauseLinkText:          'Pause Slideshow',
					prevLinkText:           '&lsaquo; Previous Photo',
					nextLinkText:           'Next Photo &rsaquo;',
					//nextPageLinkText:       'NEXT PAGE',
					//prevPageLinkText:       'PREVIOUS PAGE',
					enableHistory:          false,
					autoStart:              false,
					onChange:               function(prevIndex, nextIndex) {
						$('#'+currentView+'View ul.thumbs').children()
							.eq(prevIndex).fadeTo('fast', onMouseOutOpacity).end()
							.eq(nextIndex).fadeTo('fast', 1.0);
					},
					onTransitionOut:        function(callback) {
						$('#caption').fadeTo('fast', 0.0);
						$('#slideshow').fadeTo('fast', 0.0, callback);
					},
					onTransitionIn:         function() {
						$('#slideshow').fadeTo('fast', 1.0);
						$('#caption').fadeTo('fast', 1.0);
					}/*,
					onPageTransitionOut:    function(callback) {
						$('#thumbs ul.thumbs').fadeTo('fast', 0.0, callback);
					},
					onPageTransitionIn:     function() {
						$('#thumbs ul.thumbs').fadeTo('fast', 1.0);
					}*/
				});
	});
	
	$("#paging-next").click(function(){	
		if($("#current_val").html() == $("#final_val").html()) {	
			$("#paging-next").disable();
		}
	});
	
	$("#paging-prev").click(function() {
		if($("#current_val").html() == 1) {
			$("#paging-prev").disable();
		}
	});
});



function showdiv(id,url)
{
	var currentID =  $("#curr_id").val();
	var projectType = id.split('-');
	//alert(projectType[1])
	
	if(projectType[1] == 'images') {
		$('#nav-container').fadeIn('slow');
	}else if(projectType[1] == 'flash') {
		$('#nav-container').fadeOut('slow');
	}
	
	$("#link_"+projectType[0]).show().fadeIn('slow');
	
	if( currentID== '' || currentID == null) {
		$("#curr_id").val(id);
		
		$("#black-bg").slideDown("slow",function(){
			$(this).toggleClass("active"); 
			return false;
		});
		
		var v=currentID.split("_");
		var r=v[1].split("-");
		$("#flash_"+r[0]).toggle();
		

	} else if(currentID == this.id) {
		$("#curr_id").val(id);
		
		var v=currentID.split("_");
		var r=v[1].split("-");

		$("#flash_"+r[0]).toggle();
		$("#black-bg").slideToggle("slow");
		$(this).toggleClass("active"); 
		
		return false;
	} else if(currentID != id) {
		$("#curr_id").val(id);
		
		$("#black-bg").slideDown("slow",function(){
			
			$(this).toggleClass("active"); 
			return false;
		});
		
		$("#link_"+currentID.split('-')[0]).hide();
		
	}
	
}
