$(document).ready(function() 
{

	var tabContainers = $('div.tabs > div');
	tabContainers.hide().filter(':first').show();

	$('div.tabs ul.tabNavigation a').click(function () {
		tabContainers.hide();
		tabContainers.filter(this.hash).fadeIn("slow");
		$('div.tabs ul.tabNavigation a').removeClass('selected');
		$(this).addClass('selected');
		return false;
	}).filter(':first').click();
	
	
	
	$("#most-tabs").tabs({ fx: { opacity: 'toggle' } });
	$("#top-tabs").tabs({ fx: { opacity: 'toggle' } });
	$("#list-tabs").tabs({ fx: { opacity: 'toggle' } });
	$('#online-now').vTicker({
	   speed: 2000,
	   pause: 6000,
	   showItems: 1,
	   //animation: 'fade',
	   mousePause: true,
	   height: 0,
	   direction: 'up'
	});
	

	var sites = { cwsw: 'cwsw', livejasmin: 'lj', cams: 'cams', streamate: 'streamate', dailypeep: 'dailypeep', chat49: 'chat49', xlovecam: 'xlove', webcams: 'webcams', imlive: 'imlive', camz: 'camz', camcontacts: 'camcontacts', eurolive: 'eurolive', myfreecams: 'mfc', neoncams: 'neon', needlive: 'needlive', f4f: 'f4f', privatefeeds: 'privatefeeds', camsluts: 'camsluts', directsex: 'ds', naked: 'naked', easywebcamgirls: 'easy', hotcamsclub: 'hcc', ifriends: 'ifriends', secretfriends: 'sf', peekshows: 'peeks', camwithher: 'camwithher', webcamclub: 'webcamclub', spread4u: 'sp4'};
	
	$("a[href*='modelbio']").attr('target','_blank');
	$("a[href*='modelbio']").attr('rel','nofollow');
	$("a[class*='cwsw']").attr('target','_blank');
	$("a[href*='camsites/goto']").attr('target','_blank');
	$("a[href*='wikipedia']").attr('target','_blank');
	$("a[href*='wikipedia']").attr('class','external');
	$("a[class*='external']").attr('target','_blank');
	 
	$.each(sites, function(site,icon) {
	  $('a[rel="' + site + '"]').
	    css({
	      paddingLeft: '18px',
	      background: 'transparent url("http://z.mycamgirl.net/common/images/camsites/icons/' + icon + '-16x16.png") no-repeat center left'
	    });
	});
	
	$.fn.qtip.styles.mystyle = { 
      width: 245,
      border: { width: 2, radius: 2, color: '#F3E984' },
      background: '#FFF8A9', 'font-size': '0.9em', 'font-family': 'Arial', textAlign: 'left'
	}
    
	$.fn.qtip.styles.mystyle2 = {
      border: { width: 2, radius: 2, color: '#DEDEDE' },
      background: '#F0F0F0', 'font-size': '0.7em', 'font-family': 'Arial', textAlign: 'center' 
	}
    
	$.fn.qtip.styles.mycamgirlStyle = { 
      width: 241,
      border: { width: 1, radius: 1, color: '#d6d2b2' },
      padding: 3,
      background: '#f3f0db', 'font-family': 'Arial',
      tip: {
         corner: 'bottomMiddle',
         color: '#d6d2b2',
         size: {
            x: 20,
            y : 8
         }
        }
	}
	
	$.fn.qtip.styles.cwswStyle = { 
      width: 241,
      border: { width: 1, radius: 1, color: '#f1c7f2' },
      padding: 3,
      background: '#fad2fc', 'font-family': 'Arial',
      tip: {
         corner: 'bottomMiddle',
         color: '#f1c7f2',
         size: {
            x: 20,
            y : 8
         }
        }
	}
	
   $('a.camsite').each(function()
   {    
   var file = $(this).attr('rel').toLowerCase()

      $(this).qtip(
      {
		content: {url: 'http://mycamgirl.net/tooltip/'+file+'.html'},
		position: { corner: { target: 'topMiddle', tooltip: 'bottomMiddle' } },
		hide: { when: 'mouseout', fixed: true },
		style: 'mystyle'
      });      
   });
   
   $('a.mycamgirl').each(function()
   {    
      $(this).qtip(
      {
		content: { url: 'http://mycamgirl.net/tooltip/tooltip.review.php?camgirl=' + $(this).attr('title') },
		position: { corner: { target: 'topMiddle', tooltip: 'bottomMiddle' } },
		hide: { when: 'mouseout', fixed: true },
		style: 'mycamgirlStyle'
      });
   });
   
   $('a.cwsw').each(function()
   {
      $(this).qtip(
      {
		content: { url: 'http://mycamgirl.net/tooltip/tooltip.cwsw.php?camgirl=' + $(this).attr('text') },
		position: { corner: { target: 'topMiddle', tooltip: 'bottomMiddle'} },
		hide: { when: 'mouseout', fixed: true },
		style: 'cwswStyle'
      });
   });
   
   
   $('a.imagepreview').each(function()
   {
      var content = '<img src="http://z.mycamgirl.net/mycamgirl/images/posts/galleries/' + $(this).attr('rel') + '.jpg" alt="Loading thumbnail... ' + $(this).attr('title') + ' " /><br />';
      content += '<b>' + $(this).attr('title') + '</b><br />available in the RAR file';

      $(this).qtip(
      {
		content: content,
		position: { corner: { target: 'topMiddle', tooltip: 'bottomMiddle' } },
		style: 'mystyle2'
      });
   });
   
         $("#s").attr({ value: 'write a nickname...' }).focus(function(){
            if($(this).val()=="write a nickname..."){
               $(this).val("");
            }
       }).blur(function(){
            if($(this).val()==""){
               $(this).val("write a nickname...");
            }
       });


	function log(event, data, formatted) {
		//$("<li>").html( !data ? "No match!" : "Selected: " + formatted).appendTo("#result");
		//load review
		location.href = "http://mycamgirl.net/review/"+data[1];
	}
	
	function formatItem(row) {
		return row[0] + " (<strong>id: " + row[1] + "</strong>)";
	}
	function formatResult(row) {
		return row[0].replace(/(<.+?>)/gi, '');
	}
	
	$("#s").autocomplete("http://mycamgirl.net/jquery-autocomplete.php", {
		width: 350,
		scrollHeight: 500,
		selectFirst: false,
		minChars: 3,
		max: 5,
		formatItem: function(data, i, n, value) {
			return "<img src='http://z.mycamgirl.net/mycamgirl/images/posts/headshots/" + data[0] + ".gif' /><div class='details'><p class='title'>" + data[0] +"</p><p>Downloads: "+data[3]+"</p><p>Views: "+data[4]+"</p></div>";
			//$model|$post_name|$title|$dl|$vw
		}
	});

	$(":text, textarea").result(log).next().click(function() {
		$(this).prev().search();
	});
  
});


function loadjscssfile(filename, filetype){
 if (filetype=="js"){ //if filename is a external JavaScript file
  var fileref=document.createElement('script')
  fileref.setAttribute("type","text/javascript")
  fileref.setAttribute("src", filename)
 }
 else if (filetype=="css"){ //if filename is an external CSS file
  var fileref=document.createElement("link")
  fileref.setAttribute("rel", "stylesheet")
  fileref.setAttribute("type", "text/css")
  fileref.setAttribute("href", filename)
 }
 if (typeof fileref!="undefined")
  document.getElementsByTagName("head")[0].appendChild(fileref)
}
