jQuery.noConflict();

jQuery(document).ready(function() {
							
	function boldPagination(index) {
		row = Math.ceil(index/6);
		jQuery('.jcarousel-control a.numPaginate').removeClass('strong');
		jQuery('.jcarousel-control a.row' + row).addClass('strong');
		showHideNextPrev(row);
	}
	
	function showHideNextPrev(page) {
		if(page != 1) {
			jQuery('#thumbcarousel-prev').css('color', '#000').css('cursor', 'pointer');
		} else {
			jQuery('#thumbcarousel-prev').css('color', '#ccc').css('cursor', 'default');	
		}
		numRows = jQuery('.jcarousel-control a.numPaginate:last').text();
		if(page != numRows) {
			jQuery('#thumbcarousel-next').css('color', '#000').css('cursor', 'pointer');
		} else {
			jQuery('#thumbcarousel-next').css('color', '#ccc').css('cursor', 'default');
		}
	}
	
	function changeContent(id) {
		newContent = jQuery('#content_structure .id-' + id).html();
		contentDiv = jQuery('#product_content');
		currentId = contentDiv.attr('rel');
		
		if(id != currentId) {
			contentDiv.fadeOut(100, function() {
				jQuery(this).html(newContent).fadeIn(100);
				contentDiv.attr('rel', id);
			});
		}
	}
	
	function changeDownloads(id) {
		newDownloads = jQuery('#downloads_structure .id-' + id).clone();
		downloadsDiv = jQuery('#product_downloads');
		downloadsUl = jQuery('#product_downloads ul');
		currentId = downloadsDiv.attr('rel');
		
		if(id != currentId) {
			downloadsDiv.fadeOut(100, function() {
				downloadsUl.html(newDownloads);
				jQuery(this).fadeIn(100);
				downloadsDiv.attr('rel', id);
			});
		}
	}
								
	function thumbcarousel_initCallback(carousel) {
		jQuery('.jcarousel-control a.row1').addClass('strong');
		
		jQuery('#thumbcarousel-next').bind('click', function() {
			carousel.next();
			boldPagination(carousel.last);
			return false;
		});
		jQuery('#thumbcarousel-prev').bind('click', function() {
			carousel.prev();
			boldPagination(carousel.last);
			return false;
		});
		jQuery('.jcarousel-control a.numPaginate').bind('click', function() {
			carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()*6-6));
			boldPagination(carousel.last);
			return false;
		}); 
	}
		
	jQuery('#thumbcarousel').jcarousel({
		scroll: 6,
		buttonNextHTML: null,
		buttonPrevHTML: null,
		initCallback: thumbcarousel_initCallback, 
    });
	
	jQuery('.row1').show(1000);
	
	jQuery('.mainThumbLink').fadeTo(1000, 0.4).css('cursor', 'default');

	jQuery('a.thumbLink').click(function (event) {

		event.preventDefault();

		mainUrl = jQuery('.mainImg').attr('src');
		newUrl = jQuery(this).attr('name');
		clickedThumb = jQuery(this);
		
		contentId = jQuery(this).attr('rel');
		if(contentId > 0) {
			changeContent(contentId);
			changeDownloads(contentId);
		}

		if(mainUrl != newUrl) {
			jQuery('.thumbLink').fadeTo('fast', 1.0).css('cursor', 'pointer');
			clickedThumb.fadeTo('fast', 0.4).css('cursor', 'default');

			jQuery('.mainImg').fadeOut(1000, function() {
				jQuery('.mainImg').load(function() { jQuery(this).fadeIn(1000).removeClass('loading'); }).attr('src', newUrl).addClass('loading');
			});
		
		}

	});
});