/*$(window).bind('load',function(){
	setTimeout(function(){
		$('#overlay').fadeOut(function(){
			$('body').css('overflow', 'auto');
		});
	}, 750);
})*/

function load_smaction(){
	$('a.mhss').click(
		function(event){
			$("#smenu_holder li").filter(".mhss_sel").removeClass("mhss_sel");
			$("#smenu_holder li div").filter("#ssmenu_holder").remove();
			$(this).parent().addClass("mhss_sel");
			$(this).parent().append('<div id="ssmenu_holder">&nbsp;</div>');
			var pclass = $(this).attr("id").replace("_", " ");
			var attr = $(this).attr("title");
			var type = 0;
			if ($(this).hasClass("t3")) type = 3;
			if ($(this).hasClass("t4")) type = 4;
			$("#ssmenu_holder").load("scripts/get_smenu.php",{'class':encodeURIComponent(pclass),'c':encodeURIComponent(attr),'type':type},function(){
				$('#ssmenu_holder').fadeIn('fast');
			});
			return false;	
		}
	);
}

function load_xlg(pos){
	var image = js_gimages[pos]+"_lg.jpg";
	$('#xlg_box').fadeOut(function(){
		$.post('scripts/get_image_size.php',{image:image},function(data){
			var wh = $(window).height();
			var size = data.split('|');
			var image_width = size[0];
			var image_height = size[1];
			var scroll = $(window).scrollTop();
			var top_pos = 0;
			var ch = parseInt(image_height)+40;
			top_pos = Math.round((wh-ch)/2)+scroll;
			if (top_pos<0) top_pos = 0;
			var neww = parseInt(image_width)+40;
			var newh = parseInt(image_height)+40;
			var nav_pos = Math.round((newh-103)/2);
			$('#xlg_navl').animate({'top':nav_pos+'px'},{queue:true});
			$('#xlg_navr').animate({'top':nav_pos+'px'},{queue:true});
			$('#xlg_holder').animate({'top':top_pos+'px','width':neww+'px','height':newh+'px'},{queue:true});
			$('#xlg_cholder').animate({'width':neww+'px','height':newh+'px'},{queue:true});
			$('#xlg_content').animate({'width':image_width+'px','height':image_height+'px'},{queue:true});
			$('#xlg_box').css({'width':image_width+'px','height':image_height+'px'});
			$('#xlg_icontent').animate({'width':image_width+'px','height':image_height+'px'},function(){
				var img = new Image();
				$(img).load(function () {
					$('#xlg_box').html(this);
					$('#xlg_box').fadeIn(function(){
						loaded_xlg = pos;
						$.post('scripts/get_lifestyle_info.php',{image:image},function(data){
							if (data!=''){
								$('#xlg_box').append('<div id="xlg_info">Products in this photo: '+data+'</div>');
								$('#xlg_info').css('width',(parseInt(image_width)-20)+'px');
								$('#xlg_info').fadeIn();
							}
						});
					});
				}).error(function () {
				
				}).attr('src', image)
				.css({'width': image_width+'px','height': image_height+'px'});
			
			});
		});
	});
}


function open_xlg(pos){
	var content = '<div id="xlg"><div id="xlg_holder"><div id="xlg_navl"><a href="#">previous</a></div><div id="xlg_navr"><a href="#">next</a></div><div id="xlg_cholder"><a id="xlg_close" href="#">Close</a><div id="xlg_content"><div id="xlg_icontent" class="loader_small"><div id="xlg_box">&nbsp;</div></div></div></div></div></div>';
	var ch = $('#page_holder').height();
	var wh = $(window).height();
	var scroll = $(window).scrollTop();
	var top_pos = 0;
	var img_count = js_gimages.length;	
	$('body').prepend(content);
	var xlgh = parseInt($('#xlg_holder').css('height'));
	top_pos = Math.round((wh-xlgh)/2)+scroll;
	if (top_pos<0) top_pos = 0;
	$('#xlg').css({'height':ch+'px'});
	$('#xlg_holder').css({'top':top_pos+'px'});
	$('#xlg').fadeIn(function(){
		$(document).keyup(function(event){
		    if (event.keyCode == 27 && $('#xlg').length>0) {
		        $('#xlg').hide().remove();
		    }
		});
		if (img_count>1){
			$('#xlg_navl').fadeIn();
			$('#xlg_navr').fadeIn();
		}
		load_xlg(pos);
	});
}

var phome_activity = 0;
var loaded_xlg = 0;
var activity = 0;


$(document).ready(function(){
	var active_gallery = 0;

	$('#xlg_navl a').live('click',function(){
		var prev_pos = parseInt(loaded_xlg) - 1;
		if(prev_pos in js_gimages){
			// ok
		}
		else{
			prev_pos = js_gimages.length-1;
		}
		load_xlg(prev_pos);
		return false;
	});

	$('#xlg_navr a').live('click',function(){
		var next_pos = parseInt(loaded_xlg) + 1;
		if(next_pos in js_gimages){
			// ok
		}
		else{
			next_pos = 0;
		}
		load_xlg(next_pos);
		return false;
	});

	$('#xlg_close').live('click',function(){
		$('#xlg').hide().remove();
		return false;
	});

	$('div.galleryd_ls_tn ul li a').click(function(){
		var pos = $(this).attr('id').replace('ls_','');
		open_xlg(pos);
		return false;
	});
	
	$('#prod_lgb_tn ul li a').live('click',function(){
		var pos = $(this).attr('id').replace('ls_','');
		open_xlg(pos);
		return false;
	});	
	
	if ($('#prod_lgb_tn_navl a').length>0){
		$('#prod_lgb_tn_navl a').live('click',function(){
			if (activity==0){
				activity = 1;
				var count = $('#prod_lgb_tn ul li').size();
				var pos = $('#prod_lgb_tn ul').css('left').replace('px','');
				var left_count = -pos/55;
				if (left_count>6) left_count = 6;
				if (left_count>0){
					$('#prod_lgb_tn ul').animate({'left':'+='+(left_count*55)+'px'},function(){
						activity = 0;
					});
				}
				else{
					activity = 0;
				}
			}
			return false;
		})
	
	}
	if ($('#prod_lgb_tn_navr a').length>0){
		$('#prod_lgb_tn_navr a').live('click',function(){
			if (activity==0){
				activity = 1;
				var count = $('#prod_lgb_tn ul li').size();
				var pos = $('#prod_lgb_tn ul').css('left').replace('px','');
				var right_count = count + pos/55 - 6;
				if (right_count>6) right_count = 6;
				if (right_count>0){
					$('#prod_lgb_tn ul').animate({'left':'-='+(right_count*55)+'px'},function(){
						activity = 0;
					});
				}
				else{
					activity = 0;
				}
			}
			return false;
		})
	
	}

	if ($('#phome_nav').length>0){
		$('#phome_prev').live('click',function(){
			if (phome_activity==0){
				phome_activity = 1;
				var pinfo = $('#phome_inner').attr('class').replace('phomep_','').split('_');
				var page = parseInt(pinfo[0]);
				var pages = parseInt(pinfo[1]);
				if (page-1>0) page = page-1;
				else page = pages;
				$('#phome_infoc').fadeOut(function(){
					$('#phome_info').addClass('loader_small');
					$.post('scripts/get_phome.php',{page:page},function(data){
						var info = data.split('<|>');
						var info1 = info[0];
						var info2 = info[1];
						var info3 = info[2];

						$('#ctop_phome_box2').remove();
						$('#ctop_phomec').prepend('<div id="ctop_phome_box2">&nbsp;</div>');
						$('#ctop_phomec').css({'left':'-784px'});

						$('#ctop_phome_box2').html(info1);
						$('#phome_infoc').html(info2);
						$('#phome_inner').attr('class','phomep_'+info3);

						$('#ctop_phomec').animate({'left':'0px'},function(){
							$('#ctop_phome_box1').remove();	
							$('#ctop_phomec').css({'left':'0px'});
							$('#ctop_phome_box2').attr('id','ctop_phome_box1');
							$('#ctop_phomec').append('<div id="ctop_phome_box2">&nbsp;</div>');
							$('#phome_info').removeClass('loader_small');
							$('#phome_infoc').fadeIn(function(){
								phome_activity = 0;
							});
						});

						
					});
				
				});
			}
			return false;
		});
		$('#phome_next').live('click',function(){
			if (phome_activity==0){
				phome_activity = 1;
				var pinfo = $('#phome_inner').attr('class').replace('phomep_','').split('_');
				var page = parseInt(pinfo[0]);
				var pages = parseInt(pinfo[1]);
				if (page+1<=pages) page = page+1;
				else page = 1;
				$('#phome_infoc').fadeOut(function(){
					$('#phome_info').addClass('loader_small');
					$.post('scripts/get_phome.php',{page:page},function(data){
						var info = data.split('<|>');
						var info1 = info[0];
						var info2 = info[1];
						var info3 = info[2];
						$('#ctop_phome_box2').html(info1);
						$('#phome_infoc').html(info2);
						$('#phome_inner').attr('class','phomep_'+info3);

						$('#ctop_phomec').animate({'left':'-784px'},function(){
							$('#ctop_phome_box1').remove();	
							$('#ctop_phomec').css({'left':'0px'});
							$('#ctop_phome_box2').attr('id','ctop_phome_box1');
							$('#ctop_phomec').append('<div id="ctop_phome_box2">&nbsp;</div>');
							$('#phome_info').removeClass('loader_small');
							$('#phome_infoc').fadeIn(function(){
								phome_activity = 0;
							});
						});

						
					});
				
				});
			}
			return false;
		});
	}


	$('div.prod_photo').addClass("loader_small");
	$('a.prod_dimg img').css({"display":"none"});
	$("a.prod_dimg img").each(function(index,el){
		var my_src = $(el).attr("src");
		var my_alt = $(el).attr("alt");
		var parent = $(el).parent();
		$(parent).html('');
		var img = new Image();
		$(img).load(function () {
			$(this).css({"display":"none"});
			$(parent).html(this);
			$(parent).parent().removeClass('loader_small');
			$(this).fadeIn();
		}).error(function () {

		}).attr('src', my_src)
		.attr('alt', my_alt);
	});

	$('div.galleryd_ib a').live('click',function(){
		var next_img = parseInt(($(this).children("img").attr("id")).replace("glgi",""))+1;
		var next_id = next_img; 
		var arrl = js_gimages.length-1;
		if (next_img>arrl){
			next_id = 0;
		}
		if (active_gallery==0){
			active_gallery = 1;
			$("#gdib2").html('<a href="#"><img src="'+js_gimages[next_id]+'_lg.jpg" id="glgi'+next_id+'" alt="" /></a>');
			$("#galleryd_ibh").animate({left:'-=497'},300,function(){
				$("div.galleryd_tn ul li a").filter(".sel").removeClass("sel");
				$("#gtni"+next_id).parent().addClass("sel");
				$("#gdib1").remove();
				$("#galleryd_ibh").css({left:0});
				$("#gdib2").attr({id:"gdib1"});
				$("#galleryd_ibh").append("<div id='gdib2' class='galleryd_ib'><\/div>");
				active_gallery = 0;
			});
		}
		return false;
	});

	$('div.galleryd_tn ul li a').click(function(){
		if (active_gallery == 0){
			active_gallery = 1;
			var my_ilink = $(this);
			var img_src = $(this).children("img").attr("src");
			var img_id = $(this).children("img").attr("id");
			var lg_img = img_src.replace("_sm.jpg","_lg.jpg");
			$("#gdib2").html('<a href="#"><img src="'+lg_img+'" id="glgi'+(img_id.replace("gtni",""))+'" alt="" /></a>');
			$("#galleryd_ibh").animate({left:'-=497'},300,function(){
				$("div.galleryd_tn ul li a").filter(".sel").removeClass("sel");
				my_ilink.addClass("sel");
				$("#gdib1").remove();
				$("#galleryd_ibh").css({left:0});
				$("#gdib2").attr({id:"gdib1"});
				$("#galleryd_ibh").append("<div id='gdib2' class='galleryd_ib'><\/div>");
				active_gallery = 0;
			});
		}
		return false;
	});

	$("div.float_menu li.dsbl a").click(function(){
		return false;
	});


	$("a.rl").click(function(){
		pcalert('<h1>Login Required</h1>Please login with your account and password.',2);
		return false;
	});
	
	/* main menu */	

	var smenu_open = 0;
	var smu = 108;
	var smhw = smu*7;
	var menu_offset = 0;
	
	$('#menu_holder li a.mhdl').click(
		function(event){
			event.stopPropagation();
			var type = 0;
			var nsc = 0;

			if ($(this).hasClass("t1")) type = 1;
			if ($(this).hasClass("t2")) type = 2;
			var nsc = $(this).hasClass("nsc")?1:0;

			var attr = $(this).attr("title");
			var pos = $(this).attr("tabindex");
			var sele = $(this);
			if (smenu_open==0){
				sele.parent().addClass('sel');
				$("#smenu_holder").load("scripts/get_smenu.php",{'class':encodeURIComponent(attr),'type':type,'nsc':nsc},function(){
					var smp = (smu*pos)-smu;
					if ($('#smenu_holder').hasClass("smenu")){
						$('#smenu_holder').css("left",(smp-menu_offset)+"px");
						$('#smenu_holder').removeClass('smenu');
					}
					if (type==2){
						$('#smenu_holder').css("left",(smp-1-menu_offset)+"px");
						$('#smenu_holder').css("width","189px");
						$('#smenu_holder').addClass("smenu");
					}
					if (nsc==0){
						load_smaction();
					}
					$('#smenu_holder').fadeIn('fast',function(){ smenu_open = 1; });				
				});

			}
			else{
				$('#smenu_holder').fadeOut('fast',function(){ 
					$("#menu_holder li").filter(".sel").removeClass('sel');
					smenu_open = 0; 
					sele.parent().addClass('sel');
					$("#smenu_holder").load("scripts/get_smenu.php",{'class':encodeURIComponent(attr),'type':type,'nsc':nsc},function(){
						var smp = (smu*pos)-smu;
						if ($('#smenu_holder').hasClass("smenu")){
							$('#smenu_holder').css("left",(smp-menu_offset)+"px");
							$('#smenu_holder').removeClass('smenu');
						}
						if (type==2){
							$('#smenu_holder').css("left",(smp-1-menu_offset)+"px");
							$('#smenu_holder').css("width","189px");
							$('#smenu_holder').addClass("smenu");
						}
						if (nsc==0){
							load_smaction();					
						}
						$('#smenu_holder').fadeIn('fast',function(){ smenu_open = 1; });				
					});
				});
			}
			return false;
		}
	);

	/* main menu end */	

	var ppr = 0;

	$('#pp_next').click( // prod promo
		function(){
			if (ppr==0){
				$('#ph_box_content').animate({left:'-=798'},300,function(){
					ppr = 1;	
					$('#pp_next').addClass('dsbl')
					$('#pp_prev').removeClass('dsbl')
				});
			}
		}		
	);

	$('#pp_prev').click( // prod promo
		function(){
			if (ppr==1){
				$('#ph_box_content').animate({left:'+=798'},300,function(){
					ppr = 0;	
					$('#pp_next').removeClass('dsbl')
					$('#pp_prev').addClass('dsbl')
				});
			}
		}		
	);

	var mm = 0;
	var mm_act = 0;
	var mm_step = 0;

	$('#mm').click( // main menu MORE
		function(){
			if (mm_act==0){
				mm_act = 1;
				if (mm==0){
					var step = (($('#menu_holder ul').width()/108)-8)*108;
					mm_step = step;
					if (smenu_open==1) $('#main_smenu').animate({left:'-='+step},300);
					$('#menu_holder ul').animate({left:'-='+step},300,function(){
						menu_offset = step;
						$('#mm').addClass('mm_sel')
						mm = 1;
						mm_act = 0;
					});
				}
				else{
					if (smenu_open==1) $('#main_smenu').animate({left:'+='+mm_step},300);
					$('#menu_holder ul').animate({left:'0'},300,function(){
						menu_offset = 0;
						$('#mm').removeClass('mm_sel')
						mm = 0;
						mm_act = 0;
					});
				}
			}
		}
	);

	var hs = 0;
	var hs_act = 0;
	var hl = 0;
	var hl_act = 0;
	$('#hs').click( // header SEARCH
		function(){
			if (hs_act==0){
				hs_act = 1;
				if (hs==0){
					if (hl==1){
						$('#hl_box').fadeOut('fast',function(){
							hl = 0;
							$('#hl').removeClass('sel')
							$('#hs_box').fadeIn('fast',function(){
								hs_act = 0;
								hs = 1;
								$('#hs').addClass('sel')
							});
						});
					}
					else{
						$('#hs_box').fadeIn('fast',function(){
							hs_act = 0;
							hs = 1;
							$('#hs').addClass('sel')
						});
					}
				}
				else{
					$('#hs_box').fadeOut('fast',function(){
						hs_act = 0;
						hs = 0;
						$('#hs').removeClass('sel')
					});
				}
			}
		}
	);

	$('#hl').click( // header LOGIN
		function(){
			if (hl_act==0){
				hl_act = 1;
				if (hl==0){
					if (hs==1){
						$('#hs_box').fadeOut('fast',function(){
							hs = 0;
							$('#hs').removeClass('sel')
							$('#hl_box').fadeIn('fast',function(){
								hl_act = 0;
								hl = 1;
								$('#hl').addClass('sel')
							});
						});
					}
					else{
						$('#hl_box').fadeIn('fast',function(){
							hl_act = 0;
							hl = 1;
							$('#hl').addClass('sel')
						});
					}
				}
				else{
					$('#hl_box').fadeOut('fast',function(){
						hl_act = 0;
						hl = 0;
						$('#hl').removeClass('sel')
					});
				}
			}
		}
	);
		
	$("div.cselect ul.cselect_list li a").click(function(){
		var my_id = $(this).parent().parent().parent().attr("id");
		var value = $(this).attr("href");
		var option = $(this).html();
		$("#"+my_id+" a.cselect_sel em").html(option);
		$("#"+my_id+" .cselect_list").toggle();
		document.location.href = value;
		return false;
	});

	$("div.cselect a.cselect_sel").click(function(event){
		event.stopPropagation();
		var my_id = $(this).parent().attr("id");
		$("ul.cselect_list").hide();
		$("#"+my_id+" .cselect_list").toggle();
		return false;
	});

	$('body').click(function(){
		$("ul.pcfselect_list").hide();
		$("ul.cselect_list").hide();
		$('#smenu_holder').fadeOut('fast',function(){ 
			$("#menu_holder li").filter(".sel").removeClass('sel');
			smenu_open = 0; 
		});
	});

	$('a.cart_tn').hover(
		function(){
			$(this).children('strong').show();
		},
		function(){
			$(this).children('strong').hide();
		}
	);

	$("#ss").click(function(){
		show_ss();
		return false;
	});

	$('.srep_box_info .srep_left a').click(function(){
		$(this).parent().parent().siblings('.srep_box_detail').toggle();
		return false;
	});

	load_pcfselect();
});

var bn = 1;
var bp = 1;

function load_pcfselect(){
	$("div.pcfselect ul.pcfselect_list li a").click(function(){
		var my_id = $(this).parent().parent().parent().attr("id");
		var value = $(this).attr("title");
		var option = $(this).html();
		var input = $("#"+my_id+" .pcfselect_list").attr("id");
		$("input#i"+input).val(value);
		$("#"+my_id+" a.pcfselect_sel em").html(option);
		$("#"+my_id+" .pcfselect_list").toggle();
		return false;
	});

	$("div.pcfselect a.pcfselect_sel").click(function(event){
		event.stopPropagation();
		var my_id = $(this).parent().attr("id");
		$(this).parent().parent().css("z-index",1000);
		if ($(this).parent().parent().hasClass("ml6"))
			$(this).parent().parent().css("margin-left","6px");
		$("#"+my_id+" .pcfselect_list").toggle();
		return false;
	});
}

function load_project(){
	$('#project_form').submit(function(){
		var my_form = document.project_form;
		var error = 0;
		$('input#iproj_name').parent('div').parent('div').removeClass('isel');
		$('input#proj_name_new').parent('div').removeClass('isel');
		if (($('input#iproj_name').val()=='' || $('input#iproj_name').val()=='#') && $('input#proj_name_new').val()==''){
			error = 1;
			$('input#iproj_name').parent('div').parent('div').addClass('isel');
			$('input#proj_name_new').parent('div').addClass('isel');
		}
		if (error == 1){
			return false;
		}
		else{
			show_loading();
			var inputs = [];
			$(':input', my_form).each(function() {
				inputs.push(this.name + '=' + encodeURIComponent(this.value));
			})  
			var sku = $('input#proj_sku').val();
			var project = ($('input#proj_name_new').val()!='')?$('input#proj_name_new').val():(($('input#iproj_name').val()!='')?$('input#iproj_name').val():'');
			$("#pcalert").dialog("close");
			jQuery.ajax({
				data: inputs.join('&'),
				url: "scripts/scr_project_add.php",
				timeout: 2000,
				error: function() {
					hide_loading();
					pcalert('<h1>Add to Projects</h1>Due to an error your request could not be processed.<br />Please try again later.',2);
				},
				success: function(r) { 
					var psku = sku;
					if (psku=='-1') psku = 'Your Shopping Cart';
					hide_loading();
					switch(r){
						case "1":
							$("#page_header_menu").load("template/header_menu.inc.php");
							pcalert('<h1>Add to Projects</h1>'+psku+' saved to '+unescape(project)+' project.',1);
							break;
						case "2":
							pcalert('<h1>Add to Projects</h1>'+psku+' already in '+unescape(project)+' Projects.',1);
							break;
						default:
							pcalert('<h1>Add to Projects</h1>Due to an error your request could not be processed.<br />Please try again later.',2);
							break;
					}
				}
			})

			return false;							
		}
	});

}

function load_pb_blog(count){
	var page = 1;
	if (count==0){
		page = bp;
	}
	else{
		page = bn;
	}
	$("#pi_news_holder").load("scripts/get_pb_blog.php?bp="+encodeURIComponent(page),function(){
	});
}

// PROMO BOX NEWS NAVIGATION
var pb_news_count = 1;
var pb_news_act = 0;
function prev_pb_news(count){
	if (pb_news_act == 0){
		pb_news_act = 1
		if (pb_news_count<=1){
			pb_news_act = 0;
			return false;
		}
		else{
			$("#news_box2").remove();
			$("#news_box1").attr({id:"news_box2"});
			$("#news_box").prepend("<div id='news_box1'><\/div>");
			$("#news_box").css({right:262});
			$("#news_box1").load("scripts/get_pb_news.php",{"np":pb_news_count-1}, function(){
				$("#news_box").animate({right:"-=262"},300,function(){
					pb_news_count--;
					pb_news_act = 0;
					if (pb_news_count<=1){
						$("#pb_news_holder a.nav_prev").addClass("dsbl");
					}
					if (pb_news_count<=count){
						$("#pb_news_holder a.nav_next").removeClass("dsbl");
					}
				});
			});
		}
	}
}

function next_pb_news(count){
	if (pb_news_act == 0){
		pb_news_act = 1;
		if (count>1){
			$("#pb_news_holder a.nav_prev").removeClass("dsbl");
		}
		if (pb_news_count>=count){
			pb_news_act = 0;
			return false;
		}
		else{
			$("#news_box2").load("scripts/get_pb_news.php",{"np":pb_news_count+1}, function(){
				$("#news_box").animate({right:"+=262"},300,function(){
					$("#news_box1").remove();
					$("#news_box").css({right:0});
					$("#news_box2").attr({id:"news_box1"});
					$("#news_box").append("<div id='news_box2'><\/div>");
					pb_news_count++;
					pb_news_act = 0;
					if (pb_news_count>=count){
						$("#pb_news_holder a.nav_next").addClass("dsbl");
					}
				});
			});
		}
	}
}

// PROMO BOX DESIGNER NAVIGATION
var pb_desgn_count = 1;
var pb_desgn_act = 0;
function prev_pb_designers(count){
	if (pb_desgn_act == 0){
		pb_desgn_act = 1;
		if (pb_desgn_count<=1){
			pb_desgn_act = 0;
			return false;
		}
		else{
			$("#dsgnr_box2").remove();
			$("#dsgnr_box1").attr({id:"dsgnr_box2"});
			$("#dsgnr_box").prepend("<div id='dsgnr_box1'><\/div>");
			$("#dsgnr_box").css({right:262});
			$("#dsgnr_box1").load("scripts/get_pb_designers.php",{"dp":pb_desgn_count-1}, function(){
				$("#dsgnr_box").animate({right:"-=262"},300,function(){
					pb_desgn_count--;
					pb_desgn_act = 0;
					if (pb_desgn_count<=1){
						$("#dsgnr_holder a.nav_prev").addClass("dsbl");
					}
					if (pb_desgn_count<=count){
						$("#dsgnr_holder a.nav_next").removeClass("dsbl");
					}
				});
			});
		}
	}
}

function next_pb_designers(count){
	if (pb_desgn_act == 0){
		pb_desgn_act = 1;
		if (pb_desgn_count>=1){
			$("#dsgnr_holder a.nav_prev").removeClass("dsbl");
		}
		if (pb_desgn_count>=count){
			pb_desgn_act = 0;
			return false;
		}
		else{
			$("#dsgnr_box2").load("scripts/get_pb_designers.php",{"dp":pb_desgn_count+1}, function(){
				$("#dsgnr_box").animate({right:"+=262"},300,function(){
					$("#dsgnr_box1").remove();
					$("#dsgnr_box").css({right:0});
					$("#dsgnr_box2").attr({id:"dsgnr_box1"});
					$("#dsgnr_box").append("<div id='dsgnr_box2'><\/div>");
					pb_desgn_count++;
					pb_desgn_act = 0;
					if (pb_desgn_count>=count){
						$("#dsgnr_holder a.nav_next").addClass("dsbl");
					}
				});
			});
		}
	}
}




function pcalert(msg,type,onok,oncancel){
	var type = type || 1;
	var oncancel = oncancel || "javascript:$(\'#pcalert\').dialog(\'close\');";
	var onok = onok || "javascript:$(\'#pcalert\').dialog(\'close\');";
	var pcab = '<div id="pcalert"><div id="pcach_top">&nbsp;</div><div id="pcach"><a id="pcach_close" href="#">Close</a><div id="pcac_top">&nbsp;</div><div id="pcac"><div id="pcactc"></div><div id="pcacbc"></div></div><div id="pcac_bottom">&nbsp;</div></div><div id="pcach_bottom">&nbsp;</div></div>';
	$("#page_holder").append(pcab);
	$("#pcactc").html(msg);
	if (type==2){
		var pcabtn1 = '<a href="javascript:void(0);" onclick="javascript:$(\'#pcalert\').dialog(\'close\');" class="pcac_btn_close">CLOSE</a>';
		$("#pcacbc").html(pcabtn1);
	}
	if (type==3){
		var pcabtn2 = '<a href="javascript:void(0);" onclick="'+onok+'"  class="pcac_btn_yes">YES</a><a href="javascript:void(0);" onclick="'+oncancel+'"  class="pcac_btn_no">NO</a>';	
		$("#pcacbc").html(pcabtn2);
	}
	if (type==4){
		var pcabtn2 = '<a href="javascript:void(0);" onclick="'+onok+'"  class="pcac_btn_yes">ADD</a><a href="javascript:void(0);" onclick="'+oncancel+'"  class="pcac_btn_no">CLOSE</a>';	
		$("#pcacbc").html(pcabtn2);
	}
	if (type==5){
		var pcabtn1 = '<a href="javascript:void(0);" onclick="javascript:$(\'#pcalert\').dialog(\'close\');'+onok+'" class="pcac_btn_close">CLOSE</a>';
		$("#pcacbc").html(pcabtn1);
	}
	$("#pcalert").dialog({ 
		modal: true, 
		width: 409,
		height: 154,
		dialogClass:"pca_theme",
		close:function(ev, ui){ $(this).remove(); }
	});	
	if (type==1){
		var t = setTimeout("$('#pcalert').dialog('close');",3000)
	}
	$("#pcach_close").click(function(){
		$("#pcalert").dialog("close");
	});

}

// SLIDE SHOW NAVIGATION

var ss_timer = '';
var ss_time = 0;

var ss_prev = 1;
var ss_next = 1;
var ss_act = 0;

function load_js(){
	
	if (ss_timer!=''){
		$("#"+ss_timer).addClass("sscb");
	}

	$("#ssi_holder").hover(
		function(){ 
			if (ss_time!=0){
				show_ss_msg(); 
			}
			stop_autoplay(); 
		},
		function(){ 
			hide_ss_msg(); 
			start_autoplay(); 
		}
	);

	$("#ssc5").click(function(){
		if (ss_timer!='ssc5'){
			$("#"+ss_timer).removeClass("sscb");
			$("#ssc5").addClass("sscb");
			ss_timer = 'ssc5';
			ss_time = 5;
			start_autoplay();
		}
		else{
			$("#ssc5").removeClass("sscb");
			ss_timer = '';
			ss_time = 0;
			stop_autoplay();
		}
		return false;
	});
	$("#ssc10").click(function(){
		if (ss_timer!='ssc10'){
			$("#"+ss_timer).removeClass("sscb");
			$("#ssc10").addClass("sscb");
			ss_timer = 'ssc10';
			ss_time = 10;
			start_autoplay();
		}
		else{
			$("#ssc10").removeClass("sscb");
			ss_timer = '';
			ss_time = 0;
			stop_autoplay();
		}
		return false;
	});
	$("#ssc15").click(function(){
		if (ss_timer!='ssc15'){ 
			$("#"+ss_timer).removeClass("sscb");
			$("#ssc15").addClass("sscb");
			ss_timer = 'ssc15';
			ss_time = 15;
			start_autoplay();
		}
		else{
			$("#ssc15").removeClass("sscb");
			ss_timer = '';
			ss_time = 0;
			stop_autoplay();
		}
		return false;
	});
}

function start_autoplay(){
	if (ss_time!=0){
		stop_autoplay();
		timerID = setInterval("next_ss();",ss_time*1000);
	}
}
function stop_autoplay(){
	if(typeof(timerID) !== 'undefined'){
		clearInterval(timerID);
	}
}

function prev_ss(){
	if (ss_act == 0){
		ss_act = 1;
		$("#ssi_box2").remove();
		$("#ssi_box1").attr({id:"ssi_box2"});
		$("#ssi_content").prepend("<div id='ssi_box1' class='ssi_box'><\/div>");
		$("#ssi_content").css({right:660});
		var cls = (typeof($("input#class").val()) !== 'undefined')?$("input#class").val():'';
		var c = (typeof($("input#c").val()) !== 'undefined')?$("input#c").val():'';
		var sc = (typeof($("input#sc").val()) !== 'undefined')?$("input#sc").val():'';
		var t = (typeof($("input#t").val()) !== 'undefined')?$("input#t").val():'';
		var q = (typeof($("input#q_search").val()) !== 'undefined')?$("input#q_search").val():'';
		var q_sku = (typeof($("input#q_sku").val()) !== 'undefined')?$("input#q_sku").val():'';
		var q_type = (typeof($("input#q_type").val()) !== 'undefined')?$("input#q_type").val():'';
		var mat = (typeof($("input#mat").val()) !== 'undefined')?$("input#mat").val():'';
		var artist = (typeof($("input#artist").val()) !== 'undefined')?$("input#artist").val():'';
		var sproj = (typeof($("input#sproj").val()) !== 'undefined')?$("input#sproj").val():'';
		$("#ssi_box1").load("scripts/get_sshow.php",{p:ss_prev,cls:cls,c:c,sc:sc,t:t,q:q,q_sku:q_sku,q_type:q_type,mat:mat,artist:artist,sproj:sproj}, function(){
			load_js();
			$("#ssi_content").animate({right:"-=660"},300,function(){
				ss_act = 0;
			});
		});
	}
}

function next_ss(){
	if (ss_act == 0){
		ss_act = 1;
		var cls = (typeof($("input#class").val()) !== 'undefined')?$("input#class").val():'';
		var c = (typeof($("input#c").val()) !== 'undefined')?$("input#c").val():'';
		var sc = (typeof($("input#sc").val()) !== 'undefined')?$("input#sc").val():'';
		var t = (typeof($("input#t").val()) !== 'undefined')?$("input#t").val():'';
		var q = (typeof($("input#q_search").val()) !== 'undefined')?$("input#q_search").val():'';
		var q_sku = (typeof($("input#q_sku").val()) !== 'undefined')?$("input#q_sku").val():'';
		var q_type = (typeof($("input#q_type").val()) !== 'undefined')?$("input#q_type").val():'';
		var mat = (typeof($("input#mat").val()) !== 'undefined')?$("input#mat").val():'';
		var artist = (typeof($("input#artist").val()) !== 'undefined')?$("input#artist").val():'';
		var sproj = (typeof($("input#sproj").val()) !== 'undefined')?$("input#sproj").val():'';
		$("#ssi_box2").load("scripts/get_sshow.php",{p:ss_next,cls:cls,c:c,sc:sc,t:t,q:q,q_sku:q_sku,q_type:q_type,mat:mat,artist:artist,sproj:sproj}, function(){
			$("#ssi_content").animate({right:"+=660"},300,function(){
				$("#ssi_content").css({right:0});
				$("#ssi_box1").remove();
				$("#ssi_box2").attr({id:"ssi_box1"});
				$("#ssi_content").append("<div id='ssi_box2' class='ssi_box'><\/div>");
				ss_act = 0;
				load_js();
			});
		});
	}
}

function show_ss_msg(){
	$("#slide_show").prepend('<div id="ss_msg">Slide Show stopped.<br />Please move your mouse<br />outsite the Slide Show to resume.</div>');
	$("#ss_msg").fadeIn();
}

function hide_ss_msg(){
	$("#ss_msg").fadeOut();
	$("#ss_msg").remove();
}

function show_ss(){
	ss_timer = '';
	ss_time = 0;
	var pcssb = '<div id="slide_show"><div id="ss_navl"><a href="javascript:void(0);" onclick="javascript:prev_ss();">previous</a></div><div id="ss_navr"><a href="javascript:void(0);" onclick="javascript:next_ss();">next</a></div><div id="ss_holder"><a id="ss_close" href="#">Close</a><div id="ss_top">&nbsp;</div><div id="ss_left">&nbsp;</div><div id="ss_middle"><div id="ss_ih"><div id="ss_ih_top">&nbsp;</div><div id="ss_ih_bottom">&nbsp;</div><div id="ssi_holder"><div id="ssi_content"><div id="ssi_box1" class="ssi_box"></div><div id="ssi_box2" class="ssi_box"></div></div></div></div></div><div id="ss_right">&nbsp;</div><div id="ss_bottom">&nbsp;</div></div></div>';
	$("#page_holder").append(pcssb);
	$("#slide_show").css("display","none");
	var cls = (typeof($("input#class").val()) !== 'undefined')?$("input#class").val():'';
	var c = (typeof($("input#c").val()) !== 'undefined')?$("input#c").val():'';
	var sc = (typeof($("input#sc").val()) !== 'undefined')?$("input#sc").val():'';
	var t = (typeof($("input#t").val()) !== 'undefined')?$("input#t").val():'';
	var q = (typeof($("input#q_search").val()) !== 'undefined')?$("input#q_search").val():'';
	var q_sku = (typeof($("input#q_sku").val()) !== 'undefined')?$("input#q_sku").val():'';
	var q_type = (typeof($("input#q_type").val()) !== 'undefined')?$("input#q_type").val():'';
	var mat = (typeof($("input#mat").val()) !== 'undefined')?$("input#mat").val():'';
	var artist = (typeof($("input#artist").val()) !== 'undefined')?$("input#artist").val():'';
	var sproj = (typeof($("input#sproj").val()) !== 'undefined')?$("input#sproj").val():'';
	$("#ssi_box1").load("scripts/get_sshow.php",{cls:cls,c:c,sc:sc,t:t,q:q,q_sku:q_sku,q_type:q_type,mat:mat,artist:artist,sproj:sproj},function(){
		ss_timer = 'ssc5';
		ss_time = 5;
		load_js();
		start_autoplay();
		$("#slide_show").css("display","block");
		$("#slide_show").dialog({ 
			modal: true, 
			width: 784,
			height: 438,
			closeOnEscape: false,
			close:function(ev, ui) { $(this).remove(); },
			open:function(ev, ui) { 
				$("div.ui-widget-overlay").css("opacity", 0.8); 
				$("div.ui-widget-overlay").css("background","#1c1e1d"); 
			}
		});	
	});
	$("#ss_close").click(function(){
		$("#slide_show").dialog("close").remove();
	});
}

function show_loading(){
	var pcl = '<div id="loading" style="position:relative; display:block; width:31px; height:31px;"><img src="images/loader.gif" alt="" style="position:relative; display:block; width:31px; height:31px;" /></div>';
	$("#page_holder").append(pcl);
	$("#loading").dialog({ 
		modal: true, 
		width: 150,
		height: 70,
		closeOnEscape: false,
		dialogClass:"loading_theme",
		open:function(ev, ui) { 
			$("div.ui-widget-overlay").css("opacity", 0.8); 
			$("div.ui-widget-overlay").css("background","#ffffff"); 
		},
		close:function(ev, ui) { $(this).remove(); }
	});	
}

function hide_loading(){
	$("#loading").dialog("close").remove();
}

function add_wish(sku){
	show_loading();
	jQuery.ajax({
		data: "sku="+escape(sku),
		url: "scripts/scr_wish_add.php",
		timeout: 2000,
		error: function() {
			hide_loading();
			pcalert('<h1>Add to Wish List</h1>Due to an error your request could not be processed.<br />Please try again later.',2);
		},
		success: function(r) { 
			hide_loading();
			switch(r){
				case "1":
					$("#page_header_menu").load("template/header_menu.inc.php");
					pcalert('<h1>Add to Wish List</h1>'+sku+' added to your Wish List.',1);
					break;
				case "2":
					pcalert('<h1>Add to Wish List</h1>'+sku+' already in your Wish List.',1);
					break;
				default:
					pcalert('<h1>Add to Wish List</h1>Due to an error your request could not be processed.<br />Please try again later.',2);
					break;
			}
		}
	})					
}

function add_project(sku){
	show_loading();
	$.get("scripts/get_projects.php",'sku='+sku,function(data){
		hide_loading();
		pcalert('<h1>Add to Project</h1>'+data,4,'javascript:$(\'#project_form\').submit();');
		$("div.pca_theme").css('overflow','visible');
		load_pcfselect();
		load_project();
	});
}


function wish_delete(id,name){
	pcalert('<h1>Remove from Wish List</h1>Are you sure your want to remove '+name+' from your Wish List',3,'javascript:document.location.href=\'scripts/scr_wish_delete.php?id='+encodeURIComponent(id)+'\';');
}

function project_delete(id,name){
	pcalert('<h1>Delete Project</h1>Are you sure your want to delete '+unescape(name)+' project ?',3,'javascript:document.location.href=\'scripts/scr_project_delete.php?proj='+name+'\';');
}

function project_idelete(id,name,project){
	pcalert('<h1>Delete Item</h1>Are you sure your want to delete '+unescape(name)+' from '+unescape(project)+' project ?',3,'javascript:document.location.href=\'scripts/scr_project_idelete.php?id='+encodeURIComponent(id)+'&proj='+project+'\';');
}

function project_empty(project,count){
	if (count!=0){
		pcalert('<h1>Empty Project</h1>Are you sure your want to remove all items from '+unescape(project)+' project ?',3,'javascript:document.location.href=\'scripts/scr_project_delete.php?proj='+project+'\';');
	}
}

function projects_empty(count){
	if (count!=0){
		pcalert('<h1>Remove Projects</h1>Are you sure your want to remove all projects?',3,'javascript:document.location.href=\'scripts/scr_project_empty.php\';');
	}
}

function project_buy(project,count){
	if (count!=0){
		pcalert('<h1>Buy Project</h1>All items will be added to your Shopping Cart and deleted from your Project. Are you sure?',3,'javascript:document.location.href=\'scripts/scr_project_buy.php?proj='+project+'\';');
	}
}

function wish_empty(count){
	if (count!=0){
		pcalert('<h1>Remove from Wish List</h1>Are you sure your want to remove all items from your Wish List?',3,'javascript:document.location.href=\'scripts/scr_wish_empty.php\';');
	}
}

function wish_buy(count){
	if (count!=0){
		pcalert('<h1>Buy Wish List</h1>All items will be added to your Shopping Cart and deleted from your Wish List. Are you sure?',3,'javascript:document.location.href=\'scripts/scr_wish_buy.php\';');
	}
}

function cart_project(){
	var sku = '-1';
	show_loading();
	$.get("scripts/get_projects.php",'sku='+sku,function(data){
		hide_loading();
		pcalert('<h1>Add to Project</h1>'+data,4,'javascript:$(\'#project_form\').submit();');
		$("div.pca_theme").css('overflow','visible');
		load_pcfselect();
		load_project();
	});
}

function cart_wish(items){
	pcalert('<h1>Save to Wish List</h1>Are you sure you want to save '+items+' item(s) to your Wish List ?',3,"javascript:document.location.href='scripts/scr_cart_wish.php';");
}

function cart_delete(itemID,itemName){
	pcalert('<h1>Remove from Shopping Cart</h1>Are you sure you want to delete "'+itemName+'" from your cart ?',3,"javascript:document.location.href='scripts/scr_cart_delete.php?itemID="+itemID+"';");
}
function cart_empty(){
	pcalert('<h1>Emtpy Shopping Cart</h1>Are you sure you want to remove all items from your cart ?',3,"javascript:document.location.href='scripts/scr_cart_empty.php';");
}

function add_fee(fee){
	show_loading();
	jQuery.ajax({
		data: "itemID=0&itemSKU=RO-Fee&itemName="+encodeURIComponent("Re-Order Fee")+"&itemQty=1&itemPrice="+encodeURIComponent(fee),
		url: "scripts/scr_cart_add.php",
		timeout: 2000,
		error: function() {
			hide_loading();
			pcalert('<h1>Add Re-Order Fee</h1>Due to an error your request could not be processed.<br />Please try again later.',2);
		},
		success: function(r) { 
			hide_loading();
			switch(r){
				case "1":
					document.location.href='cart.php';
					break;
				default:
					pcalert('<h1>Add Re-Order Fee</h1>Due to an error your request could not be processed.<br />Please try again later.',2);
					break;
			}
		}
	})						
}

function checkout(value,type,limit,fee,is_fee){
	if (type==0){
		if (parseFloat(value)<parseFloat(limit)){
			pcalert('<h1>Minimum Order Limit</h1>The minimum order limit is $'+limit+'.',2);
		}
		else{
			document.location.href='checkout.php';
		}
	}
	if (type==1){
		if (parseFloat(value)<parseFloat(limit) && is_fee==0){
			pcalert('<h1>Minimum Re-Order Limit</h1>The minimum re-order limit is $'+limit+'. A re-order fee of $'+fee+' can be applied. Do you want to apply this fee?',3,'javascript:$(\'#pcalert\').dialog(\'close\');add_fee(\''+fee+'\')');
		}
		else{
			document.location.href='checkout.php';			
		}
	}
}

function load_promo(promo,prod_id){
	$("#promo").load("template/promo_prod.inc.php",{pt:promo,pid:prod_id});
}

