$(document).ready(function () { 

	var deviceAgent = navigator.userAgent.toLowerCase();
	var agentID = deviceAgent.match(/(iphone|ipod|ipad)/);
	if (agentID) {

        $('#homeNav div a').css({"font-size":".6em","padding-left":"20px","padding-right":"20px"});
 
	}

	/* VIDEO DETECT REDIRECT */
	
	var videoRequest = window.location.hash;
	if (videoRequest && noLoadVideo == 0) { //alert('A - post'); //alert(window.location.toString().indexOf("videos"));				//$('.noLoadVideo').length == 0
		var vRf = videoRequest.toString();
		vRfS = vRf.split("#")[1].split("_");
		var videoType = vRfS[0];
		var videoID = vRfS[1];
		var loc = window.location.toString();
		//var token = $('.token').text();
	
		//alert(window.location.toString().indexOf("/videos"));
		if (videoType == "video" && window.location.toString().indexOf("/video_production") == -1) {
			window.location = "http://bluecorestudios.com/video_production/"+vRf;
		}
		if (videoType == "videos" && window.location.toString().indexOf("/videos") == -1) {
			window.location = "http://bluecorestudios.com/videos/"+vRf;
		}
		
	 	$.post(pPg, { p: 'get_video_details', token: token, i: videoID }, function(data) { //alert('post');
	 		$('#vidoeViewer').children('iframe').attr('src', data.link);
	 		$('#vidoeDescription .description').html(data.description);
	 		$('#vidoeProfolioTitle').html(data.title);
		}, "json");
		
			
	}
	

	if (doScroll == 1) {
		$('#vidoeList').jScrollPane({showArrows: true});
	}

    // #videoProduction #vidoeThumb
    $("#videoProduction .vidoeThumb").livequery('click',function () {
    	var rel = this.rel;
    	var href = this.href;
    	href = href.split("watch=")[1];
		vRfS = href.split("_");
		var videoType = vRfS[0];
		var videoID = vRfS[1];
		//var token = $('.token').text();
    	
    	$('.vidoeThumb').removeClass('selected');
    	
    	$(this).addClass('selected');
    	
    	$('#vidoeViewer').children('iframe').attr('src', rel);
	 	
	 	
		
	/*
 	$.post(pPg, { p: 'get_video_details', token: token, i: videoID }, function(data) {
	 		$('#vidoeDescription .description').html(data.description);
	 		$('#vidoeProfolioTitle').html(data.title);
		}, "json");
	 	
*/
    	
    	//window.location = "#"+href;
    	
    	//return false;
    
    });	

	var current_card_id = "";
	var current_card_tag_id = "ieXj3f6ie";
	var current_group_id = "";
	var current_group_tag_id = "";
	var current_group_name = "";
	var current_card_name = "";
	var address_book_input_focus = 0;
	var current_defualt_card_id = "";
	var AddressErrorCheck = 0;
	
	$("a, .save, .button").livequery(function(){$(this).attr("onfocus","if(this.blur)this.blur()");});
	
	//$.preloadCssImages();
	$('div, span, img, a').pngFix();
	$("a[rel^='prettyPhoto']").prettyPhoto();
	
	var contactWidth = "";
	if (($.browser.name == 'msie') && ($.os.name == 'win') && ($.browser.versionNumber >= 7)){
		contactWidth = "505px";
	}
	else {
		contactWidth = "490px";
	}
	

	$('#orders tbody tr').livequery("mouseover",function() {
		$(this).parents("tbody").children("tr").removeClass("hover");
	 	$(this).addClass("hover");
	});
	$('#orders tbody tr').livequery("mouseout",function() {
		$(this).parents("tbody").children("tr").removeClass("hover");
	});

	$('#orders tbody tr').livequery("click",function() {
	 	var orderID = $(this).find(".id").text();
	 	//var token = $(this).find(".token").text();
	 	$.post(pPg, { p: 'invoice', token: token, i: orderID }, function(html) {
	 		$("#order_viewer").children("#holder").remove();
			$("#order_viewer").html("<div id=\"holder\">"+html+"</div>");
		});
	 	$(this).parents("tbody").children("tr").removeClass("selected");
	 	$(this).addClass("selected");
	 	
	});
	
	$('#orders').livequery(function() {
		oTable = $(this).dataTable( {
			"bJQueryUI": true,
			"sPaginationType": "full_numbers"
		});
	});
	
	/* Sort immediately with columns 0 and 1 */
	$('#orders').livequery(function() {
		oTable.fnSort( [ [0,'desc']] );
	});
	
	$('#header span#links a').click(function(){
		var id = this.rel;
		if (id) {
			$('html,body').animate({scrollTop: ($("#"+id).offset().top - 126)},'slow');
			return false;
		}
	});

	$(".galleryThumb").mouseover(function(){
		var image = this.rel;
		image = image.split("designs/")[1].split(".jpg")[0] + "_large.jpg";
		$(this).parents(".text.article").find(".largeImage").css({"background-image":"url(../images/designs/"+image+")"});
		$(this).parents(".text.article").find(".galleryThumb").removeClass("selected");
		$(this).addClass("selected");
	});
	
	$(".galleryThumb").click(function(){ return false; });

		function contactOpen(){
			$(this).parent(".contactButtonWrapper").animate({
				width: contactWidth
			}, {
				duration: 300, 
				specialEasing: {
				width: 'linear'
			}, 
				complete: function() {
			}
		});
		
		$(this).parent(".contactButtonWrapper").children(".contactSlider").animate({
				width: contactWidth
			}, {
				duration: 300, 
				specialEasing: {
				width: 'linear'
			}, 
				complete: function() {
			}
		});
		
		$(this).parent(".contactButtonWrapper").children(".contactSlider .contactSliderEnd").animate({
				width: contactWidth
			}, {
				duration: 300, 
				specialEasing: {
				width: 'linear'
			}, 
				complete: function() {
			}
		});
	
		$(this).unbind();
		$(this).bind('click', contactClose);
	
		return false;
	
	};
	
	function contactClose(){
		
		$(this).parent(".contactButtonWrapper").animate({
				width: "149px"
			}, {
				duration: 570, 
				specialEasing: {
				width: 'linear'
			}, 
				complete: function() {
			}
		});
		
		$(this).parent(".contactButtonWrapper").children(".contactSlider").animate({
				width: "100px"
			}, {
				duration: 570, 
				specialEasing: {
				width: 'linear'
			}, 
				complete: function() {
			}
		});
		
		$(this).parent(".contactButtonWrapper").children(".contactSlider .contactSliderEnd").animate({
				width: "100px"
			}, {
				duration: 570, 
				specialEasing: {
				width: 'linear'
			}, 
				complete: function() {
			}
		});
	
		$(this).unbind();
		$(this).bind('click', contactOpen);
	
		return false;
		
	};
	
	$(".contactbutton").bind('click', contactOpen);
		var conEmail = "";
		conEmail = "chris";
		conEmail += "@chris";
		conEmail += "be";
		conEmail += "hn.c";
		conEmail += "o";
		conEmail += "m";
	$(".contactEmail").html(conEmail);
	$(".contactEmail").attr("href","mailto:"+conEmail);
	$(".contactbutton").attr("href","mailto:"+conEmail);
	
		var conPhone = "";
		conPhone = "73";
		conPhone += "2-";
		conPhone += "77";
		conPhone += "0";
		conPhone += "-38";
		conPhone += "09";
	$(".contactPhone").html(conPhone);

	
	var el = $("#dialog");
	var centerIt = function () {
    if (!$("#dialog")) {
        return;
    }
    var moveIt = function () {
        var winWidth = $(window).width();
        var winHeight = $(window).height();
        
        var topP = ((winHeight / 2) - ($("#dialog").height() / 2));
        
        if (topP < ($("#dialog").height() / 5)) {
        	topP = ($("#dialog").height() / 5);
        }
        
        
        $("#dialog").css("position","absolute").css("left", ((winWidth / 2) - ($("#dialog").width() / 2)) + "px").css("top", topP + "px");
    }; 
   	$(window).resize(moveIt);
    	moveIt();
	};

	centerIt();
  
	function dialog(html,title) {
		$('#dialogHolder,#oinion').fadeIn(200);
		$('#dialogHolder #dialog #body').html(html);
		$('#dialogHolder #dialog #header h3').text(title);
		centerIt();
		return false;
	};
  
  $('.dialogClose').click(function(){
	$('#dialogHolder,#oinion').fadeOut(200, function() {
		if (AddressErrorCheck == 0) {
			enableSaveBtn();
		}
		// Clear dialog
		$('#dialogHolder #dialog #body').remove();
		$('#dialogHolder #dialog').append('<div id="body"></div>');
		//current_card_id = "";
	});
	return false;
  });
  
 // $(".load_address_book").prepend(current_card_id);
  	var current_address_box_id = "kl43nl3ds";
	$(".load_address_book").livequery("click",function(){
		disableSaveBtn();
		//var token = this.rel;
		current_address_box_id = this.id;
		//current_card_id = "";
		//var current_defualt_card_id = $(this).children(".address_box").attr("class").split(" ")[1];
		var current_defualt_card_id = $("#"+current_address_box_id+"_hidden").val();
		//alert(current_defualt_card_id);
		current_card_id = current_defualt_card_id;
		
		$.post(pPg, { p: 'address_book', token: token, card_id: current_defualt_card_id }, function(html) {
			dialog(html,"Address Book");
		});
		
  		return false;
	});
	
	function disableSaveBtn() {
		$('input[type=submit]').attr('disabled', 'disabled');
		$('input[type=submit]').addClass('disabled');
	};
	
	function enableSaveBtn() {
      	$('input[type=submit]').removeAttr("disabled");
      	$('input[type=submit]').removeClass('disabled');
	};

	
	function load_client_address() {
		if ($("#"+current_address_box_id+" .address_box").length > 0) {
			//var token = $("#mainBody").find("input#token").val();
			$.post(pPg, { p: 'list_address', token: token, card_id: current_card_id }, function(html) {
				$("#"+current_address_box_id+" .address_box").html(html);
				//$("#"+current_address_box_id+" .address_box").attr("id",current_card_id);
				
				// Get detailed shipping quote
				if (current_address_box_id == "shipping_address" && $('body#order_details, body#quote_details').length > 0) {
					$('#detailed_shipping_quote').html("Loading...");
					$.post(pPg, { p: 'list_detailed_shipping_quote', token: token, card_id: current_card_id }, function(data) {
					
						//$("#detailed_shipping_quote").html(html);
						
						
						var options = '<select name="shipping_method" id="shipping_method_details">';
					      for (var i = 0; i < data.length; i++) {
					      	/*
var price = data[i].optionDisplay;
					      	var priceDollars = price+'n';
					      	priceDollars = price.split('n')[0].split('.')[0];
					      	var priceCents = price+'n';
					      	priceCents = price.split('n')[0].split('.')[1];
					      	if (!priceDollars) {
					      		priceDollars = '0';
					      	}
					      	if (!priceCents) {
					      		priceCents = '00';
					      	}
					      	if (priceCents.length == 1) {
					      		priceCents = priceCents+'0';
					      	}
					      	price = "$"+priceDollars+"."+priceCents;
*/
					      
					        options += '<option value="' + data[i].optionValue + '">' + data[i].optionDisplay + '</option>';
					        
					        var strVal = data[i].optionValue;
					        var strDis = data[i].optionDisplay;
					        if ((strVal.toLowerCase().indexOf("error") >= 0) || (strDis.toLowerCase().indexOf("error") >= 0)) {
					        	AddressErrorCheck = 1;
					        }
					        else {
					        	AddressErrorCheck = 0;
					        }
					        
					      }
					      options += '</select>';
					      
					      if (AddressErrorCheck == 1) {
					      	options = "<span class=\"alert\">ALERT</span><br>The shipping address you selected is bad. Please edit the address or select another one. Thank you.";
					      	disableSaveBtn();
		
					      }
					      else {
					      	enableSaveBtn();
					      
					      }
					      
					      $('#detailed_shipping_quote').children().remove();
					      $('#detailed_shipping_quote').html(options);
						
						
					
					}, "json");
				
				}
				
				
			});
			// set hidden fields
			$("#"+current_address_box_id+"_hidden").val(current_card_id);
		}
	};
	
	// check order_details shipping address onload
	if ($('body#order_details, body#quote_details').length > 0) {
		// get current shipping address id
		current_card_id = $('#shipping_address_hidden').val();
		current_address_box_id = "shipping_address";
		load_client_address();
	};
	
/*
	function load_detailed_shipping_quote() {
		if ($("#"+current_address_box_id+" .address_box").length > 0) {
			//var token = $("#mainBody").find("input#token").val();
			$.post(pPg, { p: 'list_detailed_shipping_quote', token: token, card_id: current_card_id }, function(html) {
				$("#detailed_shipping_quote").html(html);
				//$("#"+current_address_box_id+" .address_box").attr("id",current_card_id);
			});
			// set hidden fields
			$("#"+current_address_box_id+"_hidden").val(current_card_id);
		}
	};
*/
	$('.input').livequery(function () {
		//$(this).children('label');
	});
	$('input, textarea').livequery("focus",function () {
		var thisIs = $(this);
		if ($(this).val().length == 0) {
			$(this).parents('.input').children('label').fadeTo(330,0.50);//.addClass('focus');
			//$(this).parents('.input').children('label').addClass('focus');
		}
		else {
			$(this).parents('.input').children('label').fadeTo(330,0.00,function(){
				$(thisIs).parents('.input').children('label').hide();
			});
		}
	});
	
	$('input, textarea').livequery("keydown",function (event) {
		var thisIs = $(this);
		if ($(this).val().length == 0) {
			$(this).parents('.input').children('label').fadeTo(330,0.00);			
		}
		else {
			$(this).parents('.input').children('label').fadeTo(330,0.00,function(){
				$(thisIs).parents('.input').children('label').hide();
			});
		}
	});
	
	$('input, textarea').livequery("blur",function (event) {
		//alert('s');
		if ($(this).val().length == 0) {
			$(this).parents('.input').children('label').fadeTo(330,0.99);
			//$(this).parents('.input').children('label').removeClass('focus');
		}
	});
	
	$('input').livequery(function() {
		if ($(this).val().length >= 1) {
			$(this).parents('.input').children('label').hide();
		};
	});
	
	if ($.browser.safari){ //alert('hi');
		$('#contact #first_name').parents('.input').css({'margin-left':'4px','margin-right':'1px'});
		$('#contact .message').css({'top':'4px'});
	}
	if ($.browser.chrome){ //alert('hi');
		$('#contact #first_name').parents('.input').css({'margin-left':'4px','margin-right':'1px'});
		$('#contact .message').css({'top':'4px'});
	}
	if ($.browser.mozilla){ //alert('hi');
		$('#contact #first_name').parents('.input').css({'margin-left':'-1px','margin-right':'1px'});
		$('#contact #message').parents('.input').children('label').css({'bottom':'86px','top':'auto'});
	}

	

	$("ul.button li").livequery("click",function(){
		$(this).parent("ul").children().removeClass("selected");
		$(this).addClass("selected");
		
		var data = $(this).children(".value").text();
		data = data.split("_-");
		//var token = data[0];
		data = data[1];
		var thisIs = $(this);

	 	$.post(pPg, { p: data, token: token }, function(html) {
	 		$(thisIs).parents("#myaccount").find("#page_holder").remove();
			$(thisIs).parents("#myaccount").find("#page").html("<div id=\"page_holder\">"+html+"</div>");
		});
	});

	/* 	Address Book  */
	$("#address_book").livequery(function(){
		if ($(this).length > 0) {
			sort_cards();
		}
	});
	
	// Keep "current_card" selected
	function current_card() {
		//alert(current_card_tag_id);
		if (current_card_tag_id == "") {
			current_card_tag_id = "ieXj3f6ie";
		}
		
		// Check if id exists
		$("#address_book #name .list .item.name").livequery(function(){
			// if id does not exist
			if ($("#"+current_card_tag_id).length < 1) {
				current_card_tag_id = "ieXj3f6ie";
			}
		});
		
		// Highlight current Card
		$("#address_book #name .list .item.name:first").livequery(function(){
		 	if ($("#"+current_card_tag_id).length > 0) {
				// clear all selected
				$(this).parents("#name").find(".selected").removeClass("selected");
				$("#"+current_card_tag_id).addClass("selected");
			}
		});
		
	}
	///// GROUPS ///////////////////////
	// add group
	$("#address_book .add_address_group").livequery("click",function(){
		$(this).parents("#group").find(".list").children().removeClass("selected");
		// add input
			$(this).parents("#address_book").find("#group .list").append("<input class=\"new_group_name selected\" type=\"text\" value=\"Group Name\">");
			$(".new_group_name").focus().select();
			// Clear current "current_card_id"
			current_card_id = "";
			// Clear current "Cards"
			$(this).parents("#address_book").find("#name .list .holder").remove();
			// Clear current "Card"
			$(this).parents("#address_book").find("#details .list .holder").remove();
			// Reset edit button to unselected if selected: "edit_address"
			if ($(this).parents("#address_book").find("#details .edit_address").hasClass("selected")) {
				$(this).parents("#address_book").find("#details .edit_address").removeClass("selected");
			}
			// Clear current "current_card_tag_id"
			current_card_tag_id = "ieXj3f6ie";
		return false;
	});
	// select group
	$("#address_book #group a.item").livequery("click",function(){
		var group_id = this.rel;
			// Clear "current_group_tag_id" if "All" is selected
			if (group_id == "all") {
				current_group_tag_id = "";
				current_group_name = "";
				current_group_id = "";
			}
		var group_name = $(this).text();
		//var token = $(this).parents("#address_book").children(".token").text();
		var thisIs = $(this);
		current_group_name = group_name;
		current_group_id = this.rel;
		
		
		$(this).parents("#group").find(".selected").removeClass("selected");
		$(this).addClass("selected");
				
		// mark as current selection
		$(this).parents("#address_book").find(".current").removeClass("current");
		$(this).addClass("current");
		
		current_card();
		
		// Remove blank cards
		if ($(this).parents("#address_book").find(".new_card").length == 1) {
			$(this).parents("#address_book").find(".new_card").remove();
			$(this).parents("#address_book").find("#details .list").html("");
		}
	 		$.post(pPg, { p: 'list_address_book_cards', token: token, search: group_id }, function(html) {
	 			if (html.length > 0) { 
					$(thisIs).parents("#address_book").find("#name .list .holder").remove();
					$("#address_book").find("#name .list").html(html);
					sort_cards();
				
					// clear "group_id"
					group_id = "";
				
					// Load first card in list of cards
					if ($("#"+current_card_tag_id).length == 0) {
						$(thisIs).parents("#address_book").find("#details .oinion").fadeIn(100);
						$(thisIs).parents("#address_book").find("#name .list .holder a.item:first").addClass("selected");
						var card_id = $(thisIs).parents("#address_book").find("#name .list .holder a.item:first").attr("rel");
						var card_name = $(thisIs).parents("#address_book").find("#name .list .holder a.item:first").text();
						current_card_id = card_id;
						current_card_name = card_name;
						current_card_tag_id = $(thisIs).parents("#address_book").find("#name .list .holder a.item:first").attr("id");
					
						if ($(thisIs).parents("#address_book").find("#details .edit_address").hasClass("selected")) {
							$.post(pPg, { p: 'edit_address_book_card_details', token: token, card_id: card_id }, function(html) {
	 							$(thisIs).parents("#address_book").find("#details .list .holder").remove();
								$(thisIs).parents("#address_book").find("#details .list").html("<div class=\"holder\">"+html+"</div>");
								$(thisIs).parents("#address_book").find("#details .oinion").fadeOut(100);
							});
						}
						else {
							$.post(pPg, { p: 'list_address_book_card_details', token: token, card_id: card_id }, function(html) {
	 							$(thisIs).parents("#address_book").find("#details .list .holder").remove();
								$(thisIs).parents("#address_book").find("#details .list").html("<div class=\"holder\">"+html+"</div>");
								$(thisIs).parents("#address_book").find("#details .oinion").fadeOut(100);
							});
						}
					}
				}
				if (html.length == 0) {
				//alert("a");
					$("#address_book").find("#details .list .holder").remove();
					$("#address_book").find("#name .list").html("<div class=\"holder\"></div>");
					// Do some clearing     
					current_card_tag_id = "ieXj3f6ie";
					current_card_id = "";
					// Clear current "Cards"
					// Clear current "Card"
					$("#address_book").find("#details .list .holder").remove();
					// Reset edit button to unselected if selected: "edit_address"
					if ($(thisIs).parents("#address_book").find("#details .edit_address").hasClass("selected")) {
						$(thisIs).parents("#address_book").find("#details .edit_address").removeClass("selected");
					}
				}

			});
		return false;
	});

	// Delete
	$(document).keydown(function (e) {
		var keyIs = e.which;
		
		//var token = $("#address_book").children(".token").text();
		
			if (keyIs == 8 && $("#address_book #group a.item.group.selected.current").length > 0) {
					var answer = confirm("Are you sure you want to delete the selected Group?\n\nGroup Name:\n"+current_group_name);
					if (answer) {
						$.post(pPg, { p: 'delete_address_book_group_process', token: token, card_id: current_card_id, group_id: current_group_id }, function(html) {
							var message = html.split("::")[0];
							// delete card from group
							if (message == "deleted") {
								$("#address_book #group a.item.group.selected.current").remove();
							}
							else {
								alert("Deletion of Group: '"+current_group_name+"' failed. Please try again.");
							}
							
						});
					}
				return false;
			}
			else if (keyIs == 8 && $("#address_book #name a.item.name.selected.current").length > 0) {
					// if group not is all
					if (current_group_id > 0 && $('input:focus').length == 0) {
					
						var answer = confirm("Are you sure you want to delete the selected Card from this Group?\n\nCard:\n"+current_card_name);
						if (answer) {
							// remove group_id from card in database
							$.post(pPg, { p: 'delete_address_book_card_from_group_process', token: token, group_id: current_group_id, card_id: current_card_id }, function(html) {
								var message = html.split("::")[0];
								// delete card from group
								if (message == "deleted") {
									$("#address_book #name a.item.name.selected.current").remove();
								}
								else {
									alert("Deletion of Card: '"+current_card_name+"' failed. Please try again.");
								}
							
							});
							
								var answer = confirm("Do you want to delete the selected Card from the Address Book?\n\nCard:\n"+current_card_name);
								if (answer) {
									// delete card from address book
									$.post(pPg, { p: 'delete_address_book_card_from_address_book_process', token: token, card_id: current_card_id }, function(html) {
										var message = html.split("::")[0];
										if (message == "deleted") {
										}
										else {
											alert("Deletion from Address Book failed. Please try again.");
										}
									});
								}
						}
					}
					else {
						var answer = confirm("Are you sure you want to delete the selected Card from the Address Book?\n\nCard:\n"+current_card_name);						
						if (answer) {
							// delete card from address book
							$.post(pPg, { p: 'delete_address_book_card_from_address_book_process', token: token, card_id: current_card_id }, function(html) {
								var message = html.split("::")[0];
								if (message == "deleted") {
									$("#address_book #name a.item.name.selected.current").remove();
								}
								else {
									alert("Deletion from Address Book failed. Please try again.");
								}
							});
						}
					}
				return false;
			}
			else if (keyIs == 8 && $("#address_book").length > 0 && address_book_input_focus == 0) {
					var answer = confirm("Are you sure you want to go to the previous page.");
					if (answer) {
						previousPage();
					}
				return false;
			}
	});
	
	$("#address_book #group input").livequery("click",function(){
		address_book_input_focus = 1;
	});
		
	$("#address_book #group input").livequery("focus",function(){
		address_book_input_focus = 1;
	});
	
	// edit group
	$("#address_book .item.group").livequery("dblclick",function(){
	
		var group_name = $(this).text();
		var group_id = this.rel;
		
		// replace with input
		$(this).replaceWith("<input class=\"new_group_name\" type=\"text\" name=\""+group_id+"\" value=\""+group_name+"\">");
		$(".new_group_name").focus().select();
		
		return false;
	});
	// save group
	$("#address_book .new_group_name").livequery("blur",function(){
	
		var group_name = $(this).val();
		var group_id = this.name;
		//var token = $(this).parents("#address_book").children(".token").text();
		var thisIs = $(this);
	
		
	 	$.post(pPg, { p: 'address_book_add_group_process', token: token, group_id: group_id, group_name: group_name }, function(html) {
	 		var message = html.split("::")[0];
	 		var	group_id_num = html.split("::")[1];
	 		var alertM = "Group failed to save or update. Please contact you systems administrator.";
	 			
	 			$(thisIs).replaceWith("<a href=\"#\" rel=\""+group_id_num+"\" title=\""+group_name+"\" class=\"item group selected\">"+group_name+"</a>");
				
				// Save group
				if (message == "updated failed" ) {
					alert("Group name failed to update. Please contact you systems administrator.");
				}
				else if (message == "inserted failed") {
				// Save group
					alert("New group failed to save. Please contact you systems administrator.");
				}
			sort_groups();
			
			address_book_input_focus = 0;
		});
	});
	// sort group
	function sort_groups() {
		$('#address_book #group .list').livequery(function(){
			var mylist = $(this);
			var listitems = mylist.children('.item.group').get();
	
			listitems.sort(function(a, b) {
				var compA = $(a).text().toUpperCase();
				var compB = $(b).text().toUpperCase();
			return (compA < compB) ? -1 : (compA > compB) ? 1 : 0;
			});
			$.each(listitems, function(idx, itm) { mylist.append(itm); });
		});
	}
	
	////// Cards ////
	// add new card
	$("#address_book .add_address").livequery("click",function(){
		
		// Clear current "current_card_tag_id"
		current_card_tag_id = "ieXj3f6ie";
		// Clear current "current_card_id"
		current_card_id = "";
		//var token = $(this).parents("#address_book").children(".token").text();
		var thisIs = $(this);
		
		
		// Reset edit button to unselected if selected: "edit_address"
		if ($(this).parents("#address_book").find("#details .edit_address").hasClass("selected")) {
		}
		else {
			$(this).parents("#address_book").find("#details .edit_address").addClass("selected");
		}
		
		if ($(this).parents("#address_book").find("#name .list .holder .new_card").length == 0) {
		
		// remove "selected" from selected names	
		$(this).parents("#name").find(".selected").removeClass("selected");
		
		// show oinion
		$(this).parents("#address_book").find("#details .oinion").fadeIn(100);
		
		// add input
			$(this).parents("#address_book").find("#name .list .holder").append("<a href=\"#\" name=\"No Name\" rel=\"\" title=\"\" class=\"item name selected new_card\"><i>No Name</i></a>");
			
			$.post(pPg, { p: 'address_book_new_card_form', token: token }, function(html) {
	 			$(thisIs).parents("#address_book").find("#details .list .holder").remove();	 				 			
	 			$(thisIs).parents("#address_book").find("#details .list").html("<div class=\"holder\">"+html+"</div>");
				$(thisIs).parents("#address_book").find("#details .oinion").fadeOut(100);
				sort_cards();
			});
		}
		
		return false;
	});
	// select card
	$("#address_book #name a.new_card").livequery("click",function(){return false;});
	
	$("#address_book #name a.item:not(.new_card)").livequery("click",function(){
		var card_id = this.rel;
		var card_name = $(this).text();
		//var token = $(this).parents("#address_book").children(".token").text();
		var thisIs = $(this);
		current_card_id = card_id;
		current_card_name = card_name;
		current_card_tag_id = this.id;
		
		// card highlight
		$(this).parents("#name").find(".selected").removeClass("selected");
		$(this).addClass("selected");
		
		// show oinion
		$(this).parents("#address_book").find("#details .oinion").fadeIn(100);
		
		// mark as current selection
		$(this).parents("#address_book").find(".current").removeClass("current");
		$(this).addClass("current");
		
		// Remove blank cards
		if ($(this).parents("#address_book").find(".new_card").length == 1) {
			$(this).parents("#address_book").find(".new_card").remove();
			$(this).parents("#address_book").find("#details .list").html("");
		}
		
		if ($(this).parents("#address_book").find("#details .edit_address").hasClass("selected")) {
			$.post(pPg, { p: 'edit_address_book_card_details', token: token, card_id: current_card_id }, function(html) {
	 			$(thisIs).parents("#address_book").find("#details .list .holder").remove();
				$(thisIs).parents("#address_book").find("#details .list").html("<div class=\"holder\">"+html+"</div>");
				$(thisIs).parents("#address_book").find("#details .oinion").fadeOut(100);
			});
		}
		else {
			$.post(pPg, { p: 'list_address_book_card_details', token: token, card_id: current_card_id }, function(html) {
	 			$(thisIs).parents("#address_book").find("#details .list .holder").remove();
				$(thisIs).parents("#address_book").find("#details .list").html("<div class=\"holder\">"+html+"</div>");
				$(thisIs).parents("#address_book").find("#details .oinion").fadeOut(100);
			});
		}
		
		
		
		
		// set selected card for default address
		load_client_address();
		
		
		if (AddressErrorCheck == 0) {
			enableSaveBtn();
		}
		
		return false;
	
	});
	////// DETAILS ////////
	// edit card
	$("#address_book .edit_address").livequery("click",function(){
		// add input
		//var token = $(this).parents("#address_book").children(".token").text();
		var thisIs = $(this);
		
		// Check if there is a "current_card_id"
		if (current_card_id) {
			// show oinion
			$(this).parents("#address_book").find("#details .oinion").fadeIn(100);
		
			if ($(this).hasClass("selected")) {
				// Save changes to card
				$.post(pPg, { p: 'list_address_book_card_details', token: token, card_id: current_card_id }, function(html) {
	 				$(thisIs).parents("#address_book").find("#details .list .holder").remove();
					$(thisIs).parents("#address_book").find("#details .list").html("<div class=\"holder\">"+html+"</div>");
					$(thisIs).parents("#address_book").find("#details .oinion").fadeOut(100);
				});
				$(thisIs).removeClass('selected');
			}
			else {
				$.post(pPg, { p: 'edit_address_book_card_details', token: token, card_id: current_card_id }, function(html) {
	 				$(thisIs).parents("#address_book").find("#details .list .holder").remove();
					$(thisIs).parents("#address_book").find("#details .list").html("<div class=\"holder\">"+html+"</div>");
					$(thisIs).parents("#address_book").find("#details .oinion").fadeOut(100);
				});
				$(thisIs).addClass('selected');
		
			}
		}
		// remove empty card
		else {
			// Remove blank cards
			if ($(this).parents("#address_book").find(".new_card").length == 1) {
				$(this).parents("#address_book").find(".new_card").remove();
				$(this).parents("#address_book").find("#details .list").html("");
			}
		}
		
		// clear labels
		
		if ($("#address_book").find("#details .list input").length > 0) {
			$("#address_book").find("#details .list input").parent(".input").children("label").hide();
		}
		
		return false;
	});

	$("#address_book #details input").livequery("click",function(){
		address_book_input_focus = 1;
		$(this).parents("#address_book").find(".current").removeClass("current");
	});
		
	$("#address_book #details input").livequery("focus",function(){
		address_book_input_focus = 1;
		$(this).parents("#address_book").find(".current").removeClass("current");
	});
	
	// Save Card
	$("#address_book #details input").livequery("blur",function(){
		// add input		
		var input_val = $(this).val();
		var input_name = $(this).attr("name");
		//var token = $(this).parents("#address_book").children(".token").text();
		var thisIs = $(this);
		var inputs = $(this).parents(".holder").find("input");
		var inputs_values_str = "";
		$.each(inputs, function(idx, itm) {
			inputs_values_str += $.trim($(itm).val());
		});
		
		if (inputs_values_str) {
			$.post(pPg, { p: 'address_book_add_card_process', token: token, card_id: current_card_id, card_name: input_name, card_value: input_val, group_id: current_group_id }, function(html) {
	 			
	 				var message = html.split("::")[0];
	 				var	card_id = html.split("::")[1].split(":L8s3:")[0];
	 				var	name = html.split(":L8s3:")[1].split(":3s8L:")[0];
	 				var	sort_name = html.split(":L8s3:")[1].split(":3s8L:")[1];

	 				if (message == "updated") {
					
						$("#address_book #name a.item.name.selected").replaceWith('<a class="item name selected" title="'+name+'" rel="'+card_id+'" name="'+sort_name+'" href="#" id="card_'+card_id+'" onfocus="if(this.blur)this.blur()">'+name+'</a>');

						current_card_id = card_id;

						sort_cards();
					}
					if (message == "inserted") {
				
						$("#address_book #name a.item.name.selected").replaceWith('<a class="item name selected" title="'+name+'" rel="'+card_id+'" name="'+sort_name+'" href="#" id="card_'+card_id+'" onfocus="if(this.blur)this.blur()">'+name+'</a>');
					
						current_card_id = card_id;
				
						sort_cards();
					}
					if (card_id && message != "inserted" && message != "updated") {
						$("#address_book #name a.item.name.selected").replaceWith("<a href=\"#\" name=\"No Name\" id=\"card_"+current_card_id+"\" rel=\""+current_card_id+"\" title=\"\" class=\"item name selected new_card\"><i>No Name</i></a>");
					}

				// Clear "input_val"
				input_val = "";
				inputs_values_str = "";
			});
		}
		address_book_input_focus = 0;
		// set selected card for default address
		load_client_address();
		
		
		if (AddressErrorCheck == 0) {
			enableSaveBtn();
		}
		
		return false;
	});

	// sort cards
	function sort_cards() {
		$('#address_book #name .list .holder').livequery(function(){
			var mylist = $(this);
			var listitems = mylist.children('.item.name').get();
			listitems.sort(function(a, b) {
				var compA = $(a).attr("name").toUpperCase();
				var compB = $(b).attr("name").toUpperCase();
			return (compA < compB) ? -1 : (compA > compB) ? 1 : 0;
			});
			$.each(listitems, function(idx, itm) { mylist.append(itm); });
		});
	}
	
	var address_book_drag_card_id = "";
	var address_book_drag_cat_id = "";
	$("#address_book #name a.item:not(.new_card)").livequery(function () {
		$(this).draggable({
		   start: function(event, ui) {
		   address_book_drag_card_id = this.rel;
		   },
		   drag: function(event, ui) {
		   		$('.ui-draggable.ui-draggable-dragging').css({'background-color':'red'});
		   },
		   stop: function(event, ui) {
		   },
			revert: 'invalid',
			revertDuration: 200,
			helper: 'clone',
			zIndex: 10000000000,
			cursorAt: { left: 27 },
			stack: '.list',
			containment: '#address_book',
			appendTo: '#address_book',
		});
	});
	$("#group .list .item.group").livequery(function () {
		$(this).droppable({
			drop: function(event, ui) {
				// DO NOT EVER REMOVE THE FOLLOWING LINE //
				setTimeout(function() { ui.draggable.remove(); }, 1); // yes, even 1ms is enough
				// DO NOT EVER REMOVE THE ABOVE LINE //
				var address_book_drag_cat_id = this.rel;
				//var token = $(this).parents("#address_book").children(".token").text();
				var thisIs = $(this);
				$(this).css({'background-color':''});
				$('.ui-draggable.ui-draggable-dragging').css({'background-color':'red'});
				$(ui.draggable).replaceWith(ui.draggable.clone());
				$('.ui-draggable.ui-draggable-dragging').remove();
				// Update card with new category_id
				$.post(pPg, { p: 'address_book_add_card_to_category_process', token: token, card_id: address_book_drag_card_id, group_id: address_book_drag_cat_id });
								
			},
			over: function(event, ui) {
				$(this).css({'background-color':'#FFFF99'});
			},
			out: function(event, ui) {
				$(this).css({'background-color':''});
			},
			 accept: 'a.item:not(.new_card)'
		});
	});
	
	
	// SAVE FORMS
	
		// profile
		$("#profile .save").livequery("click",function () {
			////var token = $("#mainBody").find("input#token").val();
			$.post(pPg, $(this).parents("#profile").serialize(), function(html) {
				
			});
			return false;
		});
		
		$("#profile").livequery("submit",function () {
			////var token = $("#mainBody").find("input#token").val();
			$.post(pPg, $(this).parents("#profile").serialize(), function(html) {
				
			});
			return false;
		});	
		
		
		
/////////// SHOPPING CART //////////////////

	// bind the recalc function to the quantity fields
	$("input[id^='qty_item_']").livequery("keyup", recalc);
	$("#shipping_method").livequery("change", recalc);

	function rowPrice(numberDays,rowPrice) {
	
				//var rowPrice = parseFloat($(this).parents('tr').find('.lineTotalOriginal').val());
				//var numberDays = parseFloat($(this).parents('tr').find('.number_days').val());
				
				// update price
				if (days % 7 === 0) {
				alert('p0');
					price = ( (price * days) * .4 );
				}
				else if (days > 7 && days < 13) {
				alert('p1');
					price = ( ( (price * 7) * .4 ) + ( (days - 7) * price ) );
				}
				else if (days > 12 && days < 15) {
				alert('p2');
					price = ( ( (price * 7) * .4 ) + ( (days - 7) * price ) );
				}
				else {
				alert('p3');
					var dayCount = ( days - (days % 7) );
					var dayCountRemaining = (days % 7);
					
					price = ( ( (price * dayCount) * .4 ) + ( dayCountRemaining * price ) );
					
				}
				
				price * qty;
				
				return newPrice;
	
	}
	
		//"if (days % 7 === 0) {alert('p0');price = ( (price * days) * .4 );}else if (days > 7 && days < 13) {alert('p1');price = ( ( (price * 7) * .4 ) + ( (days - 7) * price ) );}else if (days > 12 && days < 15) {alert('p2');price = ( ( (price * 7) * .4 ) + ( (days - 7) * price ) );}else {alert('p3');var dayCount = ( days - (days % 7) );var dayCountRemaining = (days % 7);alert(dayCount+' - '+dayCountRemaining);price = ( ( (price * dayCount) * .4 ) + ( dayCountRemaining * price ) );}price * qty;"

//(billableDays / 7)
	
	function recalc(){
	
		$("[id^=total_item]").calc(
			// the equation to use for the calculation   .395327942
			
			
"if (days % 7 === 0) {price = ( (price * days) * (billableDays / 7) );}else if (days > 7 && days < 13) {price = ( ( (price * 7) * (billableDays / 7) ) + ( (days - 7) * price ) );}else if (days > 12 && days < 15) {price = ( ( (price * 7) * (billableDays / 7) ) + ( (days - 7) * price ) );}else {var dayCount = ( days - (days % 7) );var dayCountRemaining = (days % 7);price = ( ( (price * dayCount) * (billableDays / 7) ) + ( dayCountRemaining * price ) );}price * qty;"
			
			,
			// define the variables used in the equation, these can be a jQuery object
			{
				qty: $("input[id^=qty_item_]"),
				price: $("[id^=price_item_]"),
				days: $("[id^=number_days_]"),
				billableDays: $("[id^=billableDays_]")
			},
			// define the formatting callback, the results of the calculation are passed to this function
			function (s){
				// return the number as a dollar amount
				return "$" + s.toFixed(2);
				
				
				
			},
			// define the finish callback, this runs after the calculation has been complete
			function ($this){
				// sum the total of the $("[id^=total_item]") selector
				var sum = $this.sum();
				
				$("#cartSubTotal").text(
					// round the results to 2 digits
					"$" + sum.toFixed(2)
				);
				
				var shipping = parseFloat($('#shipping_method').val());
				if (!shipping) {
					shipping = 0;
				}
				
				if ($('#shipping').text() !== "FREE") {
					$('#shipping').text("$" + (shipping.toFixed(2)));
				}
				
							
				
				sum = sum + shipping;
				var tax = 0;
				sum = sum + tax;
				
				$("#cartTotal").text(
					// round the results to 2 digits
					"$" + (sum.toFixed(2))
				);
			}
		);
	};
	
	//alert(  28 % 7 === 0  );
	
	
	$('.number_days').livequery("keyup", function(){
		//recalc();
		var days = $(this).val();
		var id = $(this).parents('table').attr('class');
		$.post(pPg, { id: id, days: days, p: "update_shipping_cart_item_days", token: token }, function(data) {
			//shippingQuote('#shipping_zipcode');
			recalc();
		});
	});
	
	//cartRowId_
	$("input[id^='qty_item_']").livequery("keyup", function(){
		//var token = $(this).parents('table').find('.token').val();
		var qty = $(this).val();
		var id = $(this).parents('tr').attr('id');
		$.post(pPg, { id: id, qty: qty, p: "update_shipping_cart_item_quantity", token: token }, function(data) {
			shippingQuote('#shipping_zipcode');
			
		});
	});
	$(".selectDays").change( function(){
		//var token = $(this).parents('table').find('.token').val();
		//var qty = $(this).val();
		var id = $(this).parents('table').attr('class');
		var val = $(this).val();
		//var rowPrice = parseFloat($(this).parents('tr').find('.lineTotalOriginal').val());
		//var numberDays = parseFloat($(this).parents('tr').find('.number_days').val());
		
		var billable_type = val.split('_')[1];
		var days = parseFloat(val.split('_')[0]);

				
		if (days == 0) {
			days = 1;
			$(this).parents('td').children('input').show();
		}
		else if (days == 7) {
			$(this).parents('td').children('input').hide();
		}
		else {
			$(this).parents('td').children('input').hide();
		}
		
		$(this).parents('td').children('input').val(days);
		
		
		
		$.post(pPg, { id: id, days: days, billable_type:billable_type, p: "update_shipping_cart_item_days", token: token }, function(data) {
			//shippingQuote('#shipping_zipcode');
			recalc();
		});
		
		
		
		//recalc();
		/*

		// update price
		var newPrice = 0;
		if (numberDays == 7) {
			newPrice = ( (rowPrice * 7) * .4 );
		}
		else if (numberDays > 7 && numberDays < 13) {
			newPrice = ( ( (rowPrice * 7) * .4 ) + ( (numberDays - 7) * rowPrice ) );
		}
		else if (numberDays > 12 && numberDays < 15) {
			newPrice = ( ( (rowPrice * 7) * .4 ) + ( (numberDays - 7) * rowPrice ) );
		}
		else if (numberDays % 7 === 0) {
			newPrice = ( (rowPrice * numberDays) * .4 );
		}
		
		// set new line total
		$(this).parents('tr').find('.lineTotal').val(newPrice);
		$(this).parents('tr').find('.total_item').text(newPrice);
		
*/
/*
		
		$.post(pPg, { id: id, qty: qty, p: "update_shipping_cart_item_quantity", token: token }, function(data) {
			//shippingQuote('#shipping_zipcode');
			
		});
*/
	});
	
	// get estimated shipping
	$('#shipping_zipcode').livequery("keyup", function(){
		shippingQuote('#shipping_zipcode');
	});
				
	function shippingQuote(val) {
		var thisIs = $(val);
		var zipCode = $(val).val();
		var zipCodeLength = zipCode.length; //alert(zipCodeLength);
		//var token = $(val).parents('table').find('.token').val();
		var shipping_text = "";
		if (zipCodeLength >= 5) {
			$('#shipping_zipcode_box span').html("Loading...");
			$.post(pPg, { toCode: zipCode, p: "list_shipping_quote", token: token }, function(data) {
				var options = '<select name="shipping_method" id="shipping_method">';
			      for (var i = 0; i < data.length; i++) {
			      	var price = data[i].optionDisplay;
			      	var priceDollars = price+'n';
			      	priceDollars = price.split('n')[0].split('.')[0];
			      	var priceCents = price+'n';
			      	priceCents = price.split('n')[0].split('.')[1];
			      	if (!priceDollars) {
			      		priceDollars = '0';
			      	}
			      	if (!priceCents) {
			      		priceCents = '00';
			      	}
			      	if (priceCents.length == 1) {
			      		priceCents = priceCents+'0';
			      	}
			      	price = "$"+priceDollars+"."+priceCents;
			      
			        options += '<option value="' + data[i].optionDisplay + '">' + data[i].optionValue+': '+price + '</option>';
			      }
			      options += '</select>';
			      $('#shipping_method').remove();
			      if (data[0].optionValue == 'Free Shipping' && data[0].optionDisplay == 0) {
			      	options = 'FREE SHIPPING<input name="shipping_method" type="hidden" id="shipping_method" size="10" maxlength="5" value="0">';
			      	shipping_text = "FREE";
			      }
			      else {
			      	shipping_text = "$" + ($('#shipping_method').val());
			      }
			      $('#shipping').text(shipping_text);
			      $('#shipping_zipcode_box span').html(options);
			      recalc();
			      
				recalc();
			}, "json");
		}
	
	};
	
	$('.button.quote').click(function(){
	
		var rel = this.rel
		var thisIs = $(this);
		
		//$.get(rel,function(){
		$.post(pPg, { p: "quote_rows", i: rel, token: token }, function(data) {
		
			thisIs.text("ADDED TO QUOTE");
		
		});
		
		return false;
	
	});
	
	$('#notes').livequery("keyup", function(){
		//recalc();
		var notes = $(this).val();
		$.post(pPg, { notes: notes, p: "update_shipping_cart_item_notes", token: token }, function(data) {
			//shippingQuote('#shipping_zipcode');
		});
	});
	
	
		
	/* VIDEO PAGE */
	

	
	
	//alert(elem);
	
	/* RENTALS */
	$("#categoriesList ol li ol li a.selected").parents("ol").parents("li").addClass("selected");
	$("#categoriesList ol li a.selected:not(#categoriesList ol li ol li a.selected)").parents("li").addClass("selected");
	
	//$('#categoriesList').slideUp(1);
		$('#categoriesList').animate({ opacity: "0" }, 1, function(){ 
			if ($('#categoriesList').is(":visible")) {
		        $('body.rentals #listCategories').addClass('selected');
		    }
		    else {
		    	$('body.rentals #listCategories').removeClass('selected')
		    }
		 });
        $('#categoriesListContainer').slideUp(1, function(){ 
			if ($('#categoriesList').is(":visible")) {
		        $('body.rentals #listCategories').addClass('selected');
		    }
		    else {
		    	$('body.rentals #listCategories').removeClass('selected')
		    }
		 });
        if ($('#categoriesList').is(":visible")) {
	        $('body.rentals #listCategories').addClass('selected');
	    }
	$('body.rentals #listCategories').click(function(){
		var catList = $('#categoriesList');
		var catListWrap = $('#categoriesListContainer');
		
		/*
catList.animate({
						"height": "toggle", "opacity": "toggle"
						}, "slow");
*/


	if ($('#categoriesList').is(":visible")) {
        catList.animate({ opacity: "0" }, 1000, function(){  });
        catListWrap.slideUp(600,function(){
        	$('#listCategories').removeClass('selected');
        });
        
    }
    else {
        catListWrap.slideDown(270, function(){  });
        
        catList.animate({ opacity: "1" }, 450 );
        $(this).addClass('selected');
    }


		/*

			if (catList.css('display') == "none") {
				catList.slideDown();
				catList.fadeIn();
				$(this).addClass('selected');
			}
			else {
				catList.slideUp();
				catList.fadeOut();
				$(this).removeClass('selected');
			}
*/
	
	
	
	});
	
	
	$('.print').attr( "href", "javascript:void( 0 )" ).livequery('click',function(){
	
		//$('body').children().hide();
		$('.print_area').print();
		/*
$('.print_area').clone().addClass('selected').appendTo('body');
		
		var prnt = window.print();
		
		if (prnt == true) {
			$('.print_area.selected').remove();
			$('body').children().show();
		}
*/
		
		return false;
	});
	
	
	
$('.sexy-bookmarks a.external').attr("target", "_blank");
var sexyBaseHeight = $('.sexy-bookmarks').height();
var sexyFullHeight = $('.sexy-bookmarks ul.socials').height();
if (sexyFullHeight > sexyBaseHeight) {
$('.sexy-bookmarks-expand').hover(

function() {
$(this).animate({
height: sexyFullHeight + 15 + 'px'
}, {
duration: 800,
queue: false
});
}, function() {
$(this).animate({
height: sexyBaseHeight + 'px'
}, {
duration: 800,
queue: false
});
});
}
if ($('.sexy-bookmarks-center')) {
var sexyFullWidth = $('.sexy-bookmarks').width();
var sexyBookmarkWidth = $('.sexy-bookmarks:first ul.socials li').width();
var sexyBookmarkCount = $('.sexy-bookmarks:first ul.socials li').length;
var numPerRow = Math.floor(sexyFullWidth / sexyBookmarkWidth);
var sexyRowWidth = Math.min(numPerRow, sexyBookmarkCount) * sexyBookmarkWidth;
var sexyLeftMargin = (sexyFullWidth - sexyRowWidth) / 2;
$('.sexy-bookmarks-center').css('margin-left', sexyLeftMargin + 'px');
}
/*
function wopen(url, name, w, h)
{
  // Fudge factors for window decoration space.
  // In my tests these work well on all platforms & browsers.
  var w += 32;
  var h += 96;
  var wleft = (screen.width - w) / 2;
  var wtop = (screen.height - h) / 2;
  // IE5 and other old browsers might allow a window that is
  // partially offscreen or wider than the screen. Fix that.
  // (Newer browsers fix this for us, but let's be thorough.)
  if (wleft < 0) {
    w = screen.width;
    wleft = 0;
  }
  if (wtop < 0) {
    h = screen.height;
    wtop = 0;
  }
  var winds = window.open(url,
    name,
    'width=' + w + ', height=' + h + ', ' +
    'left=' + wleft + ', top=' + wtop + ', ' +
    'location=no, menubar=no, ' +
    'status=no, toolbar=no, scrollbars=no, resizable=yes');
  // Just in case width and height are ignored
  winds.resizeTo(w, h);
  // Just in case left and top are ignored
  winds.moveTo(wleft, wtop);
  winds.focus();
}
*/

	var bcsT = document.title;
	var bcsM = window.location;

$('.sexy-bookmarks a.external').click(function(){
	var url = this.href;
	url = url.replace("bcsT", bcsT).replace("bcsM", bcsM);
	//var pTitle = document.title;
	
	var leftValw = (550 - screen.width) / 2;
	var topValw = (350 - screen.height) / 2;
	
	//wopen(url, '_bcsshare', 550, 350);
	
	var newWindow = window.open(url, '_bcsshare','height=350, width=550, scrollbars=no, toolbar=no,left='+leftValw+',top='+topValw);
	newWindow.moveTo(leftValw, topValw)
	newWindow.focus();
	
	return false;
});


	//$('.commentList').animate({ opacity: "0" }, 1 );
	$('.news .comment').click(function(){ //
		var pT = $(this).parents('.commentArea');
		
		//var vCt = pT.find('.viewAllComments .wVisSt').text("Hide");
		
		if (pT.find('.commentList').css("display") == "none") {
			pT.find('.commentList').animate({ opacity: "1" }, 450 );
			pT.find('.commentList').slideDown(250,function(){
				//var elF = $('.writeComment.focused'); //alert($(elF).offset().top);
				if (loggedIn == 1) {
					pT.find('.writeComment').focus();
					$('html,body').animate({ scrollTop: $('.writeComment.focused').offset().top }, { duration: 300});
				}
				
				pT.find('.viewAllComments .wVisSt').text("Hide");
			});
			
		}
		else {
			//$(this).parents('.commentArea').find('.commentList').hide();
			//$(this).parents('.commentArea').find('.viewAllComments').text($(this).parents('.commentArea').find('.viewAllComments').text().replace("Hide", "View"));
		}
		//pT.find('.comments').show();
		pT.find('.writeComment').focus();

	});
		
/*
	$('.commentList').livequery(function(){
	
		var commentRowCount = $(this).children('.commentRow').length;
	
		$(this).children('.commentRow:lt('+(commentRowCount - 2)+')').addClass('hideRow').hide();
		$(this).children('.commentRow:eq(0)').removeClass('hideRow').show();
	
	});
*/
/*
	
	$('.viewAllComments').click(function(){
		if ($(this).parents('.commentArea').find('.hideRow').css("display") == "none") {
			
			$(this).parents('.commentArea').find('.commentRow').show();
			$(this).text($(this).text().replace("View", "Hide Comments"));
		}
		else {
			$(this).parents('.commentArea').find('.hideRow').hide();
			$(this).text($(this).text().replace("Hide", "View"));
		}
	});
*/

	$('.commentList').animate({ opacity: "0" }, 1 );
	$('.viewAllComments').click(function(){
		var pT = $(this).parents('.commentArea');
		if (pT.find('.commentList').css("display") == "none") {
			pT.find('.commentList').animate({ opacity: "1" }, 650 );
			pT.find('.commentList').slideDown(450,function(){
				//var elF = $('.writeComment.focused'); //alert($(elF).offset().top);
				//$('html,body').animate({ scrollTop: $('.writeComment.focused').offset().top }, { duration: 300});
				pT.find('.viewAllComments .wVisSt').text("Hide");
			});
			
		}
		else {
			pT.find('.commentList').animate({ opacity: "0" }, 300 );
			pT.find('.commentList').slideUp(600);
			pT.find('.viewAllComments .wVisSt').text("View");
		}
	});

	
/*
    $('.news .text.article').livequery(function(){
		var textLength = $(this).text().length;
		
		if (textLength > 299) {
			var textToHide = $(this).html().substring(300);
	    	var visibleText = $(this).html().substring(0, 300);
	    	var visibleTextLastSpace = visibleText.lastIndexOf(" ");
	    	var visibleText = visibleText.substring(0, visibleTextLastSpace)
	        $(this).html(visibleText + ('<span class="articleText"> ' + textToHide + '</span>'))
	        .append(' <span class="read_more uiButtion" title="Read More...">Read More&hellip;</span>');
	        //.click(function() {
	           //$(this).find('.articleText').show();
	           //$(this).find('a:last').hide();
	           //$(this).html("Read Less&hellip;");
	        //});
		}
	});
*/
    $('#news .text.article .articleText').hide();
	$('#news .read_more').livequery("click",function(){
		var tA = $(this).parents('.text.post');
		//alert(tA.find('.text.article').height());
		
		if (tA.find('.text.article').height() == 32) { // close
		//if (tA.find('.text.article').css("white-space") == "normal") { //alert('close');
			tA.find('.text.article').removeAttr("style");
			tA.find('.read_more').html("Read Less");
			tA.find('.read_more').attr("title","Read Less");
			tA.find('.text.article').css({"overflow":"hidden"});
			$(this).removeClass('float');
		}
		else { // open
			tA.find('.text.article').css({"height":32, "overflow":"hidden"});
			tA.find('.read_more').html("Read More&hellip;");
			tA.find('.read_more').attr("title","Read More...");
			$(this).addClass('float');
		}
	
	});
	
	
	   $('#news .text.article').livequery(function(){
		var textLength = $(this).text().length;
		
		if (textLength > 299) {
			
			
			$(this).css({"height":32, "overflow":"hidden"});//white-space: nowrap; normal
			
			$(this).append(' <span class="read_more uiButtion float" title="Read More...">Read More&hellip;</span>')
			
		}
	});
	
/*
	
	$('.selectDays').change(function(){
	
		var val = $(this).val();
		
		if (val == 0) {
			val = 1;
			$(this).parents('td').children('input').show();
		}
		else if (val == 7) {
			$(this).parents('td').children('input').hide();
		}
		else {
			$(this).parents('td').children('input').hide();
		}
		
		$(this).parents('td').children('input').val(val);
		
	});
	
	
*/
	
	/*
if (parseFloat($('.news .text.article').find('.commentsCount').text()) == 0) {
		$('.news .text.article').find('.commentsCount').parent().hide();
	}
*/
	//font-family:'Times New Roman';color:;text-decoration:underline ;
	//html.mac body#resume div#bodyWrapper.clear div#bodyContainer div#mainBody div#mainBodyWrapper.bodyColumn div p a
	$('#resume #mainBodyWrapper a').livequery(function(){
		$(this).removeAttr('style');
	}); 

	
});
