/*!
 * Scripts
 *
 */
(function($) {

	SM = {
		utils : {
			links : function(){
				$('a[rel*=external]').click(function(e){
					e.preventDefault();
					window.open($(this).attr('href'));
				});
			},
			mails : function(){
				
				/*$('a[href^=mailto:]').each(function(){
					var mail = $(this).attr('href').replace('mailto:','');
					var replaced = mail.replace('/at/','@');
					$(this).attr('href','mailto:'+replaced);
					if($(this).text() == mail) {
						$(this).text(replaced);
					}
				});*/
			},
			samvsmark : function(){
			 $('#main #left #samvsmark').mouseover(function (e){
			   $(this).css('background-image', 'url(images/home_sam_vs_mark_box_bg_hover.png)');
			 });
			 
			 $('#main #left #samvsmark').mouseout(function (e){
			   $(this).css('background-image', 'url(images/home_sam_vs_mark_box_bg.png)');
			 });
			 
			 $('#main #left #samvsmark').click(function (e){
			 	 window.location = $('#main #left #samvsmark p.more a.interext').attr('href');
			 });
			}
		},
		ui : {
			video_overlay:function(){
				$('#videosList .thumb').mouseover(function (){
					$(this).next().css('left', '0');
				});
				
				$('#videosList .text').mouseout(function(){
					$(this).css('left', '-9999px');
				});

				$('#videosList .text').click(function(){
					window.location = $(this).attr('rel');
				});
			},
			manage_archive_links:function(){
				$('#archives ul.other').hide();
				$('#archives p.more a').click(function(){
					var curText = $(this).text();
					var linkText = '';
					$(this).parent().prev().slideToggle();
					//alert(curText);
					if(curText=='See more > '){
						linkText = 'See less > '+'<img src="images/up_face_arrow.png" />';
					}else{
						linkText = 'See more > '+'<img src="images/bottom_face_arrow.png" />';
					}
					$(this).html(linkText);						
					//alert();
				});
			},
			loadFancyBox: function(){
				$('a[rel=gal]').fancybox({'transitionIn':'none','transitionOut':'none','titlePosition':'inside','overlayColor': '#151515','titleFormat':function(title, currentArray, currentIndex, currentOpts){return '<span id="fancybox-title-over">' + (title.length ? ' &nbsp; ' + title : '') + '</span>';
					}
				});

			},
			fancyVideo: function(){

				$(".fancyVideo").fancybox({
					'width'				: 600,
					'height'			: 350,
			        'autoScale'     	: false,
			        'transitionIn'		: 'none',
					'transitionOut'		: 'none',
					'type'				: 'iframe'
				});
				
			},
			photoboth_overlay:function(){
				// $('.photoboth .img').mouseover(function (){
				// 	$(this).next().css('top', '0');
				// });
				// 
				// $('.photoboth .text').mouseout(function(){
				// 	$(this).css('top', '200px');
				// });
				// 
				// $('.photoboth .text').click(function(){
				// 	var href = $(this).prev().children("a:first-child");
				// 	window.location = href.attr('href');
				// });
				
			},
			fix_mac_samvsmark:function(){
				var OSName = '';
			  if (navigator.appVersion.indexOf("Mac")!=-1) OSName="MacOS";
			  console.dir(OSName);
			  console.dir(navigator.appVersion);
			  var brw = $.browser;
			  console.dir(brw);
			  if(OSName == 'MacOS' && brw.mozilla){
			    $('#main.samvsmark .scores .result').css('margin-top','170px');
			  }
			}

		}
	};

	SM.utils.links();
	SM.utils.samvsmark();
	SM.ui.video_overlay();
	SM.ui.photoboth_overlay();	
	SM.ui.fix_mac_samvsmark();
	//SM.utils.mails();

	SM.ui.manage_archive_links();
	
})(jQuery);
