//http://p.sohei.org/jquery-plugins/menu/
//http://p.sohei.org/stuff/jquery/menu/demo/demo.html
//http://plugins.jquery.com/project/dimensions 
$(document).ready(function(){
	
	
	setHeaderMenu();
	
	
	//image fadein
	$('img').load(function(){
		$(this).fadeIn();
	});
	
	
	setFishEyeMenu();
	
	
	setGlobalMenu();
	
	
	$("a").each(function(){addTargetBlank(this)});
	
	$('#top_artists .item').each(function(){									
		$(this).hover(
			function () {
				$(this).css('background','#FFF');
				$(this).find('a').fadeIn();
			}, 
			function () {
			}
		);
	});
	
	
	//tooltip
	var tooltip_sets = {
		track: true,
		delay: 0,
		showURL: false
	};
	$('#top_artists .item a').tooltip(tooltip_sets);
	$('#artist-page #works ul li a').tooltip(tooltip_sets);
	$('#header-menu .artists a').tooltip(tooltip_sets);
																				
	//thumbnail									
	$('#artists-thumb-list .item').each(function(){
		$(this).hover(
			function () {
				$(this).find('.img a').css('background','#FFF');
				$(this).find('a img').fadeIn();
				$(this).find('h3 a').css('borderBottom','1px solid #BFBFBF');
			}, 
			function () {
				$(this).find('h3 a').css('borderBottom','1px dotted #666');
			}
		);
	});
	
	$('#artist-page #works ul li a').each(function(){
		$(this).hover(
			function () {
				$(this).css('background','#FFF');
				$(this).find('img').fadeIn();
			}, 
			function () {
			}
		);
	});
	
	//estimate_contact
	if(location.pathname.indexOf('contact/estimate')!==-1){
		var q = getQueryParams();
		if(q && q.from) {
			var artist_name = q.from;
			$("#cf4_field_12").val(artist_name+"\n");
		}
	}
});

function getQueryParams()
{
 var qs=location.search;
 if (qs.length>1) {
  var qsa=qs.substring(1).split('&');
  var params={};
  for(var i=0; i<qsa.length; i++) {
   var pair=qsa[i].split('=');
   if (pair[0]) {
    params[pair[0]]=decodeURIComponent(pair[1]);
   }
  }
  return params;
 }
 return null;
}

//=========================================
function setHeaderMenu(){
	var manus=[];
	var hideElse=function(){
		
	}
	var showUL = function(trg){
		if($(trg).find('ul').length>0){
			var $disp_trg = $(trg+' ul');
			$(trg).hover(
				function () {
					//$disp_trg.fadeIn(300);
					$disp_trg.show();
				}, 
				function () {
					$disp_trg.hide();
				}
			);
		}
	}
	showUL('#header-menu .about');
	showUL('#header-menu .artists .name');
	showUL('#header-menu .artists .style');
	showUL('#header-menu .artists .product');
	showUL('#header-menu .artists .media');
	showUL('#header-menu .contact');
}

function setFishEyeMenu(){
	//Fisheye menu
	$('#artists-list-nav li a').attr('title','');
	if($('#artists-list-nav').length>0){
		$('#artists-list-nav').Fisheye(
			{
				maxWidth: 60,
				items: 'li',
				itemsText: 'a.title',
				container: '.dock-container',
				itemWidth: 18,
				proximity: 60,
				alignment: 'left',
				valign: 'bottom',
				halign: 'center'
			}
		);
	}
}

function addTargetBlank(trg){
	var href = $(trg).attr("href");
	if(href && href.indexOf("http://")!=-1 && href.indexOf("artas1.com")==-1){
		$(trg).attr("target","_blank");
	}
}

function setGlobalMenu(){
	$('#scroll-nav-menu').hover(
      function () {
        $(this).find(".menu").fadeIn();
      }, 
      function () {
        $(this).find(".menu").fadeOut();
      }
	);
}
function log(o){
	if(window.console) console.log(o);
}