var active_value_id;

function showAndHide(value_id) {
	$(".subproduct_info_"+active_value_id+"").slideUp(function(){
		$(".price_"+value_id).hide();
		$(".subproduct_"+value_id).addClass("selected");
		$(".subproduct_info_"+value_id).show('slow');
		$(".subproduct_"+active_value_id).removeClass("selected");
		$(".price_"+active_value_id).show();
		active_value_id = value_id;	
	});
}
function make_action(id) {
	
	$(".frame_bg").addClass("frame_head_bg_unselected");
	$(".frame_right").addClass("frame_head_right_unselected");
	$(".frame_left").addClass("frame_head_left_unselected");
	
	$("#"+id+" .frame_bg").removeClass("frame_head_bg_unselected");
	$("#"+id+" .frame_right").removeClass("frame_head_right_unselected");
	$("#"+id+" .frame_left").removeClass("frame_head_left_unselected");
	
	$("#"+id+" .frame_bg").addClass("frame_head_bg_selected");
	$("#"+id+" .frame_right").addClass("frame_head_right_selected");
	$("#"+id+" .frame_left").addClass("frame_head_left_selected");
	
	if (id == "product_review_button") {
		$("#product_description").hide();
		$("#product_question").hide();
		$("#product_review").show();
	} else if(id == "product_description_button") {
		$("#product_description").show();
		$("#product_review").hide();
		$("#product_question").hide();
	} else if(id == "product_question_button") {
		$("#product_description").hide();
		$("#product_review").hide();
		$("#product_question").show();
	}
}

function ClassImageRewinder(name) {
	this.current_pos = 0;
	this.window_height = 0;
	this.window_width = 0;
	this.container_height = 0;
	this.container_width = 0;
	this.margin = 0;
	this.cols = 0;
	this.rows = 0;
	this.th_w = 0;
	this.th_h = 0;
	this.name = name;
	this.step = 0;
	$('#'+name+'_prev').css({opacity: 0.1});
	
	this.getWindowParams = function() {
		this.window_width = $('#'+this.name+'_window').width();
		this.window_height = $('#'+this.name+'_window').height();
	}
	
	this.getContainerParams = function() {
		this.container_width = $('#'+this.name+'_container').width();
		this.container_height = $('#'+this.name+'_container').height();
	}
	
	this.getThumbParams = function() {
		this.th_w = $('.'+this.name+'_thumb').width();
		this.th_h = $('.'+this.name+'_thumb').height();
	}
	
	this.setWindowCSSParams = function(width, height) {
		$('#'+this.name+'_window').width(width);
		$('#'+this.name+'_window').height(height);
	}
	
	this.setPointerMargin = function(height) {
		$('#'+this.name+'_prev').css({'margin-top': (height/2-29)+'px'});
		$('#'+this.name+'_next').css({'margin-top': (height/2-29)+'px'});
	}
	
	this.setContainerCSSParams = function() {
		$('#'+this.name+'_container').width(this.window_width);
	}
	
	this.setDimensions = function() {
		this.cols = parseInt(this.window_width/this.th_w);
		this.rows = parseInt(this.window_height/this.th_h);
	}
	this.calculateMargin = function() {
		this.margin = parseInt(((this.window_width - this.cols * this.th_w)/this.cols)/2)-1;
	}
	this.checkPointers = function() {
		if(this.window_height>this.container_height) {
			$('#'+this.name+'_prev').hide();
			$('#'+this.name+'_next').hide();
		}
	}
	this.setMarginCSS = function() {
		$('.'+this.name+'_thumb').css({margin: this.margin+'px'});
	}
	this.rewind = function(direct) {
		$('#'+name+'_'+direct+' img').fadeOut(200, function(){$('#'+name+'_'+direct+' img').fadeIn(400);});
		if (this.step == 0) {
			this.step = this.th_h + 2 * this.margin;
		}
		if (direct == 'next' && (((this.current_pos+1) * this.step)+this.window_height-this.step) < this.container_height) {
			this.current_pos+=1;
		}
		if (direct == 'prev' && (((this.current_pos-1) * this.step)) >= 0) {
			this.current_pos-=1;
		}
		if ((((this.current_pos+1) * this.step)+this.window_height-this.step) >= this.container_height){
			$('#'+name+'_next').css({opacity: 0.1});
		} else {
			$('#'+name+'_next').css({opacity: 1});
		}
		if ((((this.current_pos-1) * this.step)) < 0) {
			$('#'+name+'_prev').css({opacity: 0.1});
		} else {
			$('#'+name+'_prev').css({opacity: 1});
		}
		this.offset = this.current_pos * this.step;
		$('#'+this.name+'_window').animate({scrollTop: this.offset}, 600);
	}
}


function CSSNested() {
	screenWidth = screen.width;
	if ($('#simpleview-main_picture').width() > (screen.width/2-260)) {
		$('#simpleview-main_picture').width(((screenWidth/2)-260));
		$('#simpleview-thumbs').width((screenWidth/2));
		$('#simpleview-thumbs_window').width((screenWidth/2)-70);
		$('#simpleview-thumbs_window').height($('#simpleview-main_picture').height());
	} else {
		$('#simpleview-main_picture').fadeIn();
		$('#simpleview-thumbs_window').width(screenWidth-$('#simpleview-main_picture').width()-120);
		$('#simpleview-thumbs').width(screenWidth-$('#simpleview-main_picture').width()-40);
	}
}

