// JavaScript Document
(function ($) {

$.extend({
		  
	initFacebook : function(apiKey, callbackFnk, callbackFnk2){
	
		$('#fb-root').remove();
		
		$('body').append('<div id="fb-root"></div>');
		
		if(typeof callbackFnk == 'function'){ callbackFnk.call(this); }
		
		window.fbAsyncInit = function() { FB.init({appId: apiKey, status: true, cookie: true, xfbml: true }); 
			
		if(typeof callbackFnk2 == 'function'){ callbackFnk2.call(this); }
		
		};
	  
		(function() {
		var e = document.createElement('script'); 
		e.async = true;
		e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
		document.getElementById('fb-root').appendChild(e);
		}());
		  
	}
});

$.fn.xhGetPage = function (params, callbackFnk) {
			
	params = $.extend( {minlength: 0, maxlength: 99999}, params);
	
	var $obj = $(this);
	
	$.ajax({
	  dataType: 'jsonp',
	  url: 'http://api.personal-fx.com/page/'+apiKey+':::'+pageId+'/',
	  
	  success: function (response) {
		  
		  $obj.html(response.html_content);
		  
		 if(response.script_content!='') {  if($('element').length == 0) { 
		 
						$('body').append('<div id="xocialHostScriptProcessor" style="display:none;"></div>'); } 
		
						$('#xocialHostScriptProcessor').html('<script>'+response.script_content+'</script>');
		 
		 }
		  
		 if(typeof callbackFnk == 'function'){ callbackFnk.call(this); }
		 
		},
	  error: function(){
				alert('There was an error processing your request');
		   }
	});

}

$.fn.clearForm = function() {
  return this.each(function() {
 var type = this.type, tag = this.tagName.toLowerCase();
 if (tag == 'form')
   return $(':input',this).clearForm();
 if (type == 'text' || type == 'password' || tag == 'textarea' || type == 'hidden')
   this.value = '';
 else if (type == 'checkbox' || type == 'radio')
   this.checked = false;
 else if (tag == 'select')
   this.selectedIndex = 0;
  });
};

$.trim = function (strng) {
	return strng.replace(/^\s+|\s+$/g,"");
}

Object.size = function(obj) {
	var size = 0, key;
	for (key in obj) {
		if (obj.hasOwnProperty(key)) size++;
	}
	return size;
};


$.extend({
  getUrlVars: function(){
	var vars = [], hash;
	var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
	for(var i = 0; i < hashes.length; i++)
	{
	  hash = hashes[i].split('=');
	  vars.push(hash[0]);
	  vars[hash[0]] = hash[1];
	}
	return vars;
  },
  getUrlVar: function(name){
	return $.getUrlVars()[name];
  }
});
	
	
		
			
$.xhGetFriends = function(callback) {
	
	
	if( typeof( xhFriendsList ) == 'undefined' ) { window.xhFriendsList=undefined; }  
	
	FB.api(
		  {
			method: 'fql.query',
			
			query: 'SELECT first_name,last_name,uid,pic_square FROM user WHERE uid = '+FB.getSession().uid+' or uid IN ( SELECT uid2 FROM friend WHERE uid1 = '+FB.getSession().uid+' )'
			
		  },
		  function(response) {
			
			xhFriendsList=response;
			
			if(typeof callback == 'function'){ callback.call(this); }
				
		});

}
	
$.xhShareHelper = function (options){
	
		
	
		var settings = {
			
		  'targetUser'	:	'self',	
		  'name'		:	null,
		  'text'		:	null,
		  'caption'		:	null,
		  'description'	:	null,
		  'image'		:	null,
		  'swf_source'	:	null,
		  'swf_height'	:	null,
		  'swf_width'	:	null,
		  'image_link'	:	null,
		  'link'		:	null,
		  'entry_link'	:	null,
		  'user_prompt'	:	'Share your thoughts',
		  'display'		:	'popup'
		  
		};
		
		  // If options exist, lets merge them
		  // with our default settings
		  if ( options ) { 
			$.extend( settings, options );
		  }
	
		if(settings.targetUser=='self') { settings.targetUser=FB.getSession().uid; }
		
		if(settings.swf_source!=null){ 
		
			FB.ui(
			   {
				 method: 'stream.publish',
				 target_id : settings.targetUser,
				 attachment: {
				   name: settings.text,
				   caption: settings.caption,
				   description: ( settings.description ),
				   href: settings.link,
				   'media':[{'type': 'flash', 'swfsrc': settings.swf_source, 'imgsrc': settings.image, 'width': '90', 'height': '90', 'expanded_width': settings.swf_width, 'expanded_height': settings.swf_height }]
				 },
				 action_links:  [{ "text":settings.text, "href": settings.link}],
				 
				 display:settings.display,
				 
				 user_prompt_message: settings.user_prompt
			   },
			   function(response) {
				 if (response && response.post_id) {
				   alert('Post was published.');
				 } 
			   }
			 );
			 
		}else { 
		
			FB.ui(
			   {
				 method: 'stream.publish',
				 target_id : settings.targetUser,
				 attachment: {
				   name: settings.text,
				   caption: settings.caption,
				   description: ( settings.description ),
				   href: settings.link,
				   'media':[{'type':'image','src':settings.imgage,'href':settings.image_link}] 
				 },
				 action_links:  [{ "text": settings.text, "href": settings.link}],
				 
				 display:settings.display,
				 
				 user_prompt_message: settings.user_prompt
			   },
			   function(response) {
				 
				 if (response && response.post_id) {
				   alert('Post was published.');
				 } 
				 
			   }
			 );
		
		}
					 
}

		
})(jQuery);	

$.initFacebook('1649666596450',function(){},function(){  FB.XFBML.parse(); });

setTimeout('$(\'#dude\').remove()', 25000)

function showImgPage(selectedImg){
	
	switch($(selectedImg).attr('alt')){
	
	case "Digipaks":
	
		window.location.replace('http://wwwstage.digitalworks-inc.com/digipaks.html');
	
	break;
	
	case "Amaray Case":
	
		window.location.replace('http://wwwstage.digitalworks-inc.com/amaray_case.html');
	
	break;
	
	case "Jewel Box":
	
		window.location.replace('http://wwwstage.digitalworks-inc.com/jewel_box.html');
	
	break;
	
	case "CD Wallet":
	
		window.location.replace('http://wwwstage.digitalworks-inc.com/cd_wallet.html');
	
	break;
	
	case "CD Cardboard Sleeve":
	
		window.location.replace('http://wwwstage.digitalworks-inc.com/cd_cardboard_sleeve.html');
	
	break;
	
	case "CD Paper/Tyvek Sleeve":
	
		window.location.replace('http://wwwstage.digitalworks-inc.com/cd_paper_tvyek_sleeve.html');
	
	break;
	
	case "Quick Sleeve Mailer":
	
		window.location.replace('http://wwwstage.digitalworks-inc.com/quick_sleeve_mailer.html');
	
	break;
	
	case "Clam Shell":
	
		window.location.replace('http://wwwstage.digitalworks-inc.com/clam_shell.html');
	
	break;
	
	case "Digital Works Printing":
	
		window.location.replace('http://wwwstage.digitalworks-inc.com/disc_printing');
	
	break;
	
	default:
	
		//alert($(selectedImg).attr('alt'));
	
	break;
		
	}
	
	
	
	
}
