var currentSection = 'features';
var nav_tabs = ['gallery', 'features', 'specs'];

$(document).ready(function(){
// methods for the modelProduct page images:
	jQuery('#mycarousel').jcarousel({
		vertical: true,
		scroll: 2
	});
																	
	$('#product_pic_views img').hide().filter(':first').show();
	$('#product_pic_thumbs a').click(function(event){
			$('#product_pic_views img').hide().filter(this.hash).show();
			return false;
		},
		function(){} // need for mouseout state
	);

	$('#top-nav-gallery .subnav li a').click(function(event) {
		selection = this.id.split('_');
		selectSection(selection[0]);
	});
	
	$('#gallery').hide();
	currentSection = param('section');
	
	if (currentSection && currentSection != 'features') {
		selectSection(currentSection);
	}
});

function selectSection(sectionName) {
	for ( i = 0; i < nav_tabs.length; i++) {
		if (nav_tabs[i] == sectionName) {
			currentSection = sectionName;
			$('#' + nav_tabs[i]).show();
			$('#top-nav-gallery ul li#' + nav_tabs[i] + '_tab').addClass('current');
		} else if (sectionName != '') {
			$('#' + nav_tabs[i]).hide();
			$('#top-nav-gallery ul li#' + nav_tabs[i] + '_tab').removeClass('current');
		}
	}
}

function param( name ) {
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

function addSection(anchor) {
	for ( i = 0; i < nav_tabs.length; i++) {
		if (nav_tabs[i] == currentSection) {
			anchor.href = anchor.href + "&section=" + currentSection;
			break;
		}
	}
}

var profiles = { centered: { height: 600, width: 810, resizable: 1, scrollbars: 1 } }
$(function() { $('.popupwindow').popupwindow(profiles); });
