$(document).ready(function(){
	$("a.fancybox").click(function() {
		$.fancybox({
				'padding'		: 0,
				'autoScale'		: false,
				'transitionIn'	: 'fade',
				'transitionOut'	: 'fade',
				'overlayColor'	: '#000',
				'overlayOpacity': 0.8,
				'width'			: 680,
				'height'		: 495,
				'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
				'type'			: 'swf',
				'swf'			: {
					'wmode'		: 'transparent',
					'allowfullscreen'	: 'true'
				}
			});

		return false;
	});
	
	$(".stylize .screens a").jqzoom({
		title: false,
		zoomWidth: 272,
		zoomHeight: 272,
		showEffect: 'fadein',
		hideEffect: 'fadeout',
		fadeoutSpeed: 'fast'
	});
	
	$(".learnmore").click(function(e) {
		e.preventDefault();
		var section = $(this).attr("href").substr(1);
		$("html, body").animate({
			scrollTop: $("a[name=" + section + "]").offset().top
		}, 400);
	});
	
	$(".backtotop").click(function(e) {
		e.preventDefault();
		$("html, body").animate({
			scrollTop: $("a[name=top]").offset().top
		}, 400);
	});

});

var expbg = 2;
var color = 'green';
var texture = 1;

function ChangeBG(val) {
	expbg = val;
	UpdateThumbs();
	UpdatePreview();
}
function ChangeColor(val) {
	color = val;
	UpdateThumbs();
	UpdatePreview();
}
function ChangeTexture(val) {
	texture = val;
	UpdateThumbs();
	UpdatePreview();
}
function UpdatePreview() {
	var newImg = 'images/customize_demo-preview.jpg';
	var newBg = '/images/spacer.gif';

	if (color != '') {
		if (texture != '') {
			newImg = 'images/customize_demo-color_' + color + '-txt' + texture + '.jpg';
		} else {
			newImg = 'images/customize_demo-color_' + color + '.jpg';
		}
	} else if (texture != '') {
		newImg = 'images/customize_demo-txt' + texture + '.jpg';
	}

	if (expbg != '')
		newBg = 'images/customize_demo-expbg_' + expbg + '.jpg';

	$('#customize_preview .largepreview').attr('src', newImg);
	$('#customize_preview .expbg').attr('src', newBg);
}
function UpdateThumbs() {
	if (expbg == '' && color == '' && texture == '')
		$('.windowblindsdemo .thumb_original img.overlay').addClass('active');
	else
		$('.windowblindsdemo .thumb_original img.overlay').removeClass('active');

	$('.windowblindsdemo .thumb_color[title!=' + color +'] img.overlay').removeClass('active');
	$('.windowblindsdemo .thumb_color[title=' + color + '] img.overlay').addClass('active');

	$('.windowblindsdemo .thumb_texture[title!=' + texture + '] img.overlay').removeClass('active');
	$('.windowblindsdemo .thumb_texture[title=' + texture + '] img.overlay').addClass('active');

	$('.windowblindsdemo .thumb_expbg[title!=' + expbg + '] img.overlay').removeClass('active');
	$('.windowblindsdemo .thumb_expbg[title=' + expbg + '] img.overlay').addClass('active');
}
function ResetDemo() {
	expbg = '';
	color = '';
	texture = '';
	UpdateThumbs();
	UpdatePreview();
}
