//ClickTale Top part
var WRInitTime=(new Date()).getTime();
//ClickTale end of Top part
	var quertstr = 'js/proxy.php?url='
	//bookmark setting	
	var bookSeting = {
		sites: ['delicious', 'digg', 'facebook','google','livejournal','slashdot','yahoo'],
		icons: "/images/bookmarks.png"	
		}	
	var node = "";
	document.observe('dom:loaded', function() {
	  $$('a.jGTip[href]').each(function(element) {
	  	var stemValue = (element.readAttribute("rel")?element.readAttribute("rel"):"");
	    new Tip(element, {
		  ajax: {
		    url: quertstr+URLEncode(element.href),
			options: {
						method: 'get', 						
						onComplete: function(transport) {
						}
					}
				},
			hideOn: { element: 'closeButton', event: 'click' },
			style: 'default',
			delay: 0.9,
			title: element.title,
			width: 470
			//hook: { tip: (stemValue ? stemValue :'topRight'), mouse: true },			
	});
			element.observe('click', function(e) {
			Event.stop(e);
			});
	  });
	  $$('a.jTip[href]').each(function(element) {
	    new Tip(element, {
		  ajax: {
		   url: quertstr+URLEncode(element.href),
			options: {
						onComplete: function(transport) {
							// you could do something here after the ajax call is finished
						}
					}
				},
			hideOn: { element: 'closeButton', event: 'click' },
			showOn: 'click',
			style: 'default',
			delay: 0.9,
			title: element.title,
			width: 300
		//	hook: { tip: 'topMiddle', mouse: true },
		//	stem: { position: 'topMiddle'}	  
	});
			element.observe('click', function(e) {
			Event.stop(e);
			});
	  });	  
	  	 	
	  $$('a.mailtofriend[href]').each(function(element) {
			
			element.observe('click', function(e) {						
				node = new Element('div', {className: 'sendfriend', style: 'display:none'}).update(
				new Element('form',{name: 'mtform',id: 'mtform',action: '/js/mailto.php',method: 'get'}).update('Friend e-mail:'
				).update(
				new Element('input', {type: 'text', id: 'email', name: 'email'})
				).insert(
				new Element('input', {type: 'submit', value: 'submit', id: 'submitBut'})
				).insert(
				new Element('input', {type: 'button', value: 'Cancel', id: 'cancelBut'})
				));						
				Modalbox.show(node, {title: element.title, width: 450, afterLoad: setObservers, onHide: removeObservers});	
				Event.stop(e);
			});
	  });		    
	});  

function URLEncode (clearString) {
  var output = '';
  var x = 0;
  clearString = clearString.toString();
  var regex = /(^[a-zA-Z0-9_.]*)/;
  while (x < clearString.length) {
    var match = regex.exec(clearString.substr(x));
    if (match != null && match.length > 1 && match[1] != '') {
    	output += match[1];
      x += match[1].length;
    } else {
      if (clearString[x] == ' ')
        output += '+';
      else {
        var charCode = clearString.charCodeAt(x);
        var hexVal = charCode.toString(16);
        output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
      }
      x++;
    }
  }
  return output;
}

jQuery(document).ready(function(){
	jQuery('#portfolio').innerfade({ speed: 'slow', timeout: 4000, type: 'sequence'}); 
	jQuery('#portfolio2').innerfade({ speed: 'slow', timeout: 4000, type: 'sequence',  containerheight: 125}); 
	jQuery('div#sbookmark').bookmark(bookSeting);
	jQuery('#TP_F_ID').css("opacity","0.5").hover(function(){jQuery(this).animate({opacity:1})},function(){jQuery(this).animate({opacity:0.5})});
	jQuery(window).scroll(function()
	{
  		jQuery('#TP_F_ID').animate({top:jQuery(window).scrollTop()+"px" },{queue: false, duration: 350});  
	});
    //when the close button at right corner of the message box is clicked 
	jQuery('#close_message').click(function()
	{
  		//the messagebox gets scrool down with top property and gets hidden with zero opacity 
		jQuery('#TP_F_ID').animate({ top:"+=15px",opacity:0 }, "slow").unbind('mouseenter mouseleave');
	});	
	}); 

	

function checkFrom(f){
	if(f.q.value.blank()){
		alert("The query string can't null!")
		f.q.focus();
		
	}else{
		var pp = $('sform').serialize(true)
		new Ajax.Request(f.action,
		{
			method:'get' ,
			parameters: pp,
			onSuccess: function(transport){
				Modalbox.show(transport.responseText , {title: 'Pick one to show search result', width: 400});	
				
				}
			}
		);
		}
		return false;
	}	
	


var hideObserver = Modalbox.hide.bindAsEventListener(Modalbox);
function setObservers() {	
	$('mtform').observe('submit',function(event){
		sfriend(Event.element(event));		
		Event.stop(event);
		});
	$('cancelBut').observe('click', hideObserver);
};
function removeObservers() {	
	$('cancelBut').stopObserving('click', hideObserver);
}
	
function sfriend(f){
	var pv = $('email').getValue();
  var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
  if(pattern.test(pv)){   
  	var pp = f.serialize(true);      
		new Ajax.Request(f.action,
		{
			method:'get' ,
			parameters: pp,
			onSuccess: function(transport){				
				Modalbox.show(transport.responseText , {title: 'Click the mail Link', width: 400});					
				}
			}
		);
  }else{  
		alert("That is not in the correct email format");
  }
	return false;
	}	
