function initPage(){	if(typeof($) == 'function'){		initCollection();		initGallery();		choosePopups();	}}function initCollection(){	$('.collection-list .box').hover(	function(){		if(!($('.inf', $(this)).is(':animated')))$('.inf', $(this)).slideDown(200);	},function(){		$('.inf', $(this)).slideUp(200);	}	);}function initGallery(){	var _hold = $('.product-detail');	IText_t();	var img_hold = $('.gallery .hold', _hold);	var gal_list = $('.gallery-list li', _hold);	for(var i = 0; i < gal_list.length ; i++){		if(gal_list.eq(i).hasClass('active')){			gal_list.eq(i).css('opacity', 0.5);			img_hold.html('<span class="zoom">zoom</span>' + gal_list.eq(i).children('.inf-hold').html());			img_hold.children('.n-img-hold').addClass('img-hold').removeClass('n-img-hold');			img_hold.children('.n-inf').addClass('inf').removeClass('n-inf');		}	}	gal_list.click(function(){		if(!($(this).hasClass('active'))){			var new_img = $(this).children('.inf-hold');			gal_list.fadeTo(200, 1).removeClass('active');			$(this).fadeTo(200, 0.5).addClass('active');			var _h = img_hold.height();			if( _h < new_img.height()) _h = new_img.height();			img_hold.animate({height: _h}, 300, function(){				img_hold.html(img_hold.html() + new_img.html());				img_hold.children('.img-hold').css('position','absolute').fadeOut(500);				img_hold.children('.n-img-hold').css('position','absolute').fadeIn(500, function(){					img_hold.children('.img-hold').remove();					img_hold.children('.inf').remove();					img_hold.children('.n-img-hold').addClass('img-hold').removeClass('n-img-hold');					img_hold.children('.n-inf').addClass('inf').removeClass('n-inf');					img_hold.children('.zoom').click(function(){ dispPopup(img_hold.children('.inf'));});				});			});		}	});	img_hold.children('.zoom').click(function(){ dispPopup(img_hold.children('.inf'));});}function IText_t(){	var _hold = $('.product-detail');	var inf_text = $('.info-text', _hold);	var inf_text_h = $('.more', _hold);	var _h = _hold.height() - inf_text_h.height() - 20;	if(_h > 0){		inf_text.css('margin-top', _h);	}}function dispPopup(b_img){	var popup_shadow = $('#popup-shadow');	var _popup = $('#popup');	var holder_h = document.getElementById('main').offsetHeight;	if(document.body.offsetHeight > holder_h ){ holder_h = document.body.offsetHeight;}	if(popup_shadow.length > 0 && _popup.length && b_img.length){		popup_shadow.css({			height: holder_h,			opacity: 0,			display:'block'		});		$('.img-hold', _popup).html(b_img.html());		_popup.css({			width: b_img.width(),			marginLeft: -b_img.width()/2		});		popup_shadow.fadeTo(300, 0.7, function(){			_popup.fadeIn(500);		});		$('.btn-close a', _popup).click(function(){			_popup.fadeOut(500, function(){				$('.img-hold', _popup).html('');				popup_shadow.fadeOut(300);			});			return false;		});	}}function choosePopups(){	var choose_fabric = $('#choose-fabric');	var choose_finish = $('#choose-finish');	choose_fabric.children('a').eq(0).hover(function() {		$(this).parent().addClass('hovered');	}, function() {		$(this).parent().removeClass('hovered');	}).click(function() {		dispPopup2(choose_fabric);		return false;	});	choose_finish.children('a').eq(0).hover(function() {		$(this).parent().addClass('hovered');	}, function() {		$(this).parent().removeClass('hovered');	}).click(function() {		dispPopup2(choose_finish);		return false;	});}function dispPopup2(_hold) {	var _box;	var _field = _hold.find(':text');	var _shadow = $('#popup-shadow');	if(_hold.get(0).id == 'choose-fabric') { _box = $('#fabric-option');}	else if(_hold.get(0).id == 'choose-finish') { _box = $('#finish-option');}	if(_shadow.length == 0) { _shadow = $('<div id="popup-shadow"></div>').appendTo(document.body);}	if(_box.length > 0) {		var holder_h = $('#main').outerHeight();		_box.appendTo(document.body);		if(document.body.offsetHeight > holder_h ) { holder_h = document.body.offsetHeight;}		_shadow.css({			height: holder_h,			opacity: 0,			display:'block'		}).fadeTo(300, 0.7, function(){			_box.fadeIn(500);		});		_box.find('.btn-close a').click(function() {			_box.fadeOut(500, function() { _shadow.fadeOut(300);});			return false;		});		_box.find('.list a').click(function(){			_field.val($(this).find('strong').text());			_field.attr('alt',$(this).attr('rel'));			recalculatePrice(_field);			_box.fadeOut(500, function() { _shadow.fadeOut(300);});			return false;		});	}}function chooseChange(){	var _hold = document.getElementById('list');	var choose_fabric = document.getElementById('choose-fabric');	var choose_finish = document.getElementById('choose-finish');	if(choose_fabric){ var choose_fabric_f = choose_fabric.getElementsByTagName('input')[0];}	if(choose_finish){ var choose_finish_f = choose_finish.getElementsByTagName('input')[0];}	if(_hold){		var _btn = _hold.getElementsByTagName('a');		for(var i = 0; i < _btn.length; i++) {			_btn[i].onclick = function() {				var _text = this.getElementsByTagName('strong')[0];				if(_text){					if(_hold.className.indexOf('fabric-option') != -1) {						if(choose_fabric_f) { choose_fabric_f.value = _text.innerHTML;}					}					if(_hold.className.indexOf('finish-option') != -1) {						if(choose_finish_f) { choose_finish_f.value = _text.innerHTML;}					}					if(typeof(tb_remove) == 'function'){ tb_remove();}				}				return false;			}		}	}}function recalculatePrice(field){	var base=0;	var fabric=0;	if($('#choose-finish input').size()>0){		base=$('#choose-finish input').attr('alt');	}	if($('#choose-fabric input').size()>0){		fabric=$('#choose-fabric input').attr('alt');	}	var data='id='+$('#id').val()+'&fabric='+fabric+'&base='+base;	$.post('ajax-calculator',data,function(data){		$('.price2').html(data);		$('#price').val(data);	},'text')}$(function(){	$('FORM.foxycart .btn-buy').click(function(){		result=true;		if($('#choose-fabric').size()>0&&!$('#choose-fabric INPUT').attr('alt')){			alert('Please choose the fabric');			result=false;		}		if($('#choose-finish').size()>0&&!$('#choose-finish INPUT').attr('alt')){			alert('Please choose the finish');			result=false;		}		return result;	})})if (window.addEventListener){	window.addEventListener("load", initPage, false);}else if (window.attachEvent){	window.attachEvent("onload", initPage);}