// MAVEN CREATIVE

$(document).ready(function () {
	
	//UP
    $("div#up a").before("<div></div>");
    $("div#up a").prev().css("opacity", "0");
    $("div#up a").hover(function(){
        $(this).prev().stop().animate({
            opacity: 1
        }, "slow");
    }, function(){
        $(this).prev().stop().animate({
            opacity: 0
        }, "slow");
    });
    
    $("div#up a").click(function(e){
        e.preventDefault();
        var target = (window.opera) ? (document.compatMode == "CSS1Compat" ? $('html') : $('body')) : $('html,body');
        target.animate({
            scrollTop: $($(this).attr("href")).offset().top
        }, 500);
    });

	
	//SMOOTH SCROLLING
   $('.sss').click(function(){
   		ssl = $(this).attr('href');
		
		$.scrollTo( ssl , 600, {easing:'easeOutQuint'} );
		
		return false;
	});
/*   
   //QTIPPIN'
   $('#qTippin a[href][title]').qtip({
   content: {
         text: false // Use each elements title attribute
      },
   position: {
      corner: {
         target: 'topMiddle',
         tooltip: 'bottomMiddle'
      }
   },
   style: {
   				 
                  border: {
                     width: 0,
                     radius: 5,
					 color:'black',
                  },
				   background: 'black',
  					color: '#ffdf00',

                  padding: 0, 
                  textAlign: 'center',
                  tip: true, // Give it a speech bubble tip with automatic corner detection
                  name: 'dark' // Style it according to the preset 'cream' style
               },

	
	});
   */
    //set timeout
	var sTimerId = 0;
	var sTime = 300;
	var cT;
	var pT;
	var nT;
   
   //photo swappin'
   $(".iPhoto").mouseenter(function(){				
			nT = $(this);	
			var thisImage = $(this).attr('href');
			var thisTarget =  $(this).attr('target');
			var targetHTML = $(thisTarget).html();
			var newHTML = '<img src="'+thisImage+'">';
			var targetD = $(this).attr('client');
			//alert("new :"+newHTML+" = old: "+targetHTML);
								
			sTimerId = setTimeout ( function(){
				if(newHTML != targetHTML)
				{
					$(thisTarget).animate({opacity: 0}, 'fast', switchOut);
					pT = cT;
					cT = nT;
				}
			}, sTime);
			function switchOut()
			{	
				$(thisTarget).html(newHTML);
				$(".dsCcontainer").html(targetD);
				$(thisTarget).animate({opacity: 1}, 'fast');
				$(cT).css({'border': 'solid', 'border-color': '#ffdf00'});
				$(pT).css({'border-color': '#ffffff'});
			}
			return false;
	});
   
   $(".iPhoto").click(function(){
			return false;
	});
    $(".iPhoto").mouseleave(function(){
			clearTimeout ( sTimerId );
			return false;
	});
	
   //video swappin'
	$(".iVideo").click(function(){
			var myHeight = $(this).attr('height');
			var myWidth = $(this).attr('width');
			var thisVid = $(this).attr('href');
			var thisT =  $(this).attr('target');
			var targetMov = '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" height="'+myHeight+'" width="'+myWidth+'"><param name="src" value="'+thisVid+'"><param name="autoplay" value="true"><param name="type" value="video/quicktime" height="'+myHeight+'" width="'+myWidth+'"><embed src="'+thisVid+'" height="'+myHeight+'" width="'+myWidth+'" autoplay="true" type="video/quicktime" pluginspage="http://www.apple.com/quicktime/download/"></object>';
			
			$(thisT).animate({opacity: 0}, 'fast', switchO);
			function switchO()
			{	
				$(thisT).html(targetMov);
				$(thisT).animate({opacity: 1}, 'fast');
			}
			return false;
	});
	//video change with desc'
	$(".iVD").click(function(){
			var myHeight = $(this).attr('height');
			var myWidth = $(this).attr('width');
			var thisVid = $(this).attr('href');
			var thisT =  $(this).attr('target');
			var targetD = $(this).attr('client');
			var targetMov = '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" height="'+myHeight+'" width="'+myWidth+'"><param name="src" value="'+thisVid+'"><param name="autoplay" value="true"><param name="type" value="video/quicktime" height="'+myHeight+'" width="'+myWidth+'"><embed src="'+thisVid+'" height="'+myHeight+'" width="'+myWidth+'" autoplay="true" type="video/quicktime" pluginspage="http://www.apple.com/quicktime/download/"></object>';
			
			$(thisT).animate({opacity: 0}, 'fast', switchO);
			function switchO()
			{	
				$(thisT).html(targetMov);
				$(thisT).animate({opacity: 1}, 'fast');
				$(".dsCcontainer").html(targetD);
			}
			return false;
	});
        
        
	//Desktop change with desc'
	$(".iDT").click(function(){
			var myHeight = $(this).attr('height');
			var myWidth = $(this).attr('width');
			var thisVid = $(this).attr('href');
			var thisT =  $(this).attr('target');
			var targetD = $(this).attr('client');
			var targetMov = '<img src="'+thisVid+'" height="'+myHeight+'" width="'+myWidth+'" />';
			
			$(thisT).animate({opacity: 0}, 'fast', switchO);
			function switchO()
			{	
				$(thisT).html(targetMov);
				$(thisT).animate({opacity: 1}, 'fast');
				$(".dsCcontainer").html(targetD);
			}
			return false;
	});
});
