/* Author:
Tibor Berki & here & there off the Intarwebs
*/

// **** remove Opacity-Filter in ie ****
function removeFilter(element) {
	if(element.style.removeAttribute){
		element.style.removeAttribute('filter');
	}
}

// JQUERY WRAPPER FIRST OPEN //
(function($) {
$(document).ready(function() {





	////// NEWS AND INTRO FADER/SCROLLER ///
	// dependencies: jquery.innerfade.js
	//$('#rotator').hide();

	$('ul.rotator-1').innerfade({ 
		animationtype: 'fade', 
		speed: 1200, 
		timeout: 12000, 
		type: 'sequence', 
		containerheight: '400px'
	}); 
	$('ul.rotator-2').innerfade({ 
		animationtype: 'slide', 
		speed: 400, 
		timeout: 15000, 
		type: 'sequence', 
		containerheight: '400px'
	});







	// POLAROID RING ON HOVER  (set opacity och fade mellan)
	$(".polle-menu li.page_item a").css("opacity","0");
	// ON MOUSE OVER
	$(".polle-menu li.page_item a").hover(function () {
	// OPACITY TO 100%
	$(this).stop().animate({
		opacity: 1.0
		}, "slow");
	},
	// ON MOUSE OUT
	function () {
		$(this).stop().animate({
			opacity: 0
		}, "slow");
	});


	// AND IMG FADE FOR PRESS LINKS ON SKI ZOOM PAGES AND MISC FADE IMGS
	$(".fade-this").css("opacity","0.6");
	// ON MOUSE OVER
	$(".fade-this").hover(function () {
	// OPACITY TO 100%
	$(this).stop().animate({
		opacity: 1.0
		}, "slow");
	},
	// ON MOUSE OUT
	function () {
		$(this).stop().animate({
			opacity: 0.6
		}, "slow");
	});

/*	// AND IMG FADE FOR PRESS LINKS ON SKI ZOOM PAGES AND MISC FADE IMGS
	$(".fade-that-popup .popupdiv").css("opacity","0.6");
	$(".fade-that-popup .popupdiv").hover(
		function () {
		$(this).stop().animate({ opacity: 1.0 }, "slow");},
		// ON MOUSE OUT
		function () {
			$(this).stop().animate({ opacity: 0.6 }, "slow");
	});
*/

	// SKIDSIDAN POPUPS SIMPLIFIED ( en ul (.popup-container) med li med element utanfor popen och en div (.popupdiv) med olika element som popupen visar. Typ.)
	$('ul.popup-container li.fade-that-popup').hover(function() {
		$('.popupdiv').css('opacity','0.4');
	  $(this).css({'z-index' : '10'});
	  $(this).find('.popupdiv').addClass('hover').stop().animate({ opacity: 1.0 }, 400)
	  } , function() {
	  $(this).css({'z-index' : '0'});
	  $(this).find('.popupdiv').removeClass('hover').stop().animate({ opacity: 0.3 }, 300)
	});

	// SKIDSIDAN POPUPS SWAP DIV ON HOVER
	$('ul.popup-container li .popupdiv').click(function() {
		var mainDiv = $(this).attr('href'); //Find Image/DIV Name
		$('#main_view .popupdiv').attr({ src: mainDiv });
		return false;		
	});




	/////// JQZOOM - SEE ALSO DEPENDENCY IN PLUGINS.JS //////
	$('.jqzoom').jqzoom({
		zoomType: 'standard',
		lens:true,
		preloadImages: true,
		zoomWidth: 730,
		zoomHeight: 600,
		xOffset:35,
		yOffset:0,
		showEffect: 'fadein',
		hideEffect: 'fadeout',
		position:'right'
  });



	////  SHOP CART KOPINFO POPUP  //////
	$(".iframe").fancybox({
		maxWidth	: 1000,
		maxHeight	: 700,
		fitToView	: false,
		width		: '85%',
		height		: '85%',
		autoSize	: false,
		closeClick	: false,
		openEffect	: 'none',
		closeEffect	: 'none'
	});



// VIDEO LIGHTBOX (on startpage)
$(".video").click(function() {
	$.fancybox({
		padding		: 0,
		autoScale		: false,
		transitionIn	: 'none',
		transitionOut	: 'none',
		title			: this.title,
		width			: 640,
		height		: 385,
		href			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
		type			: 'swf',
		swf			: {
		wmode				: 'transparent',
		allowfullscreen	: 'true'
		}
	});

	return false;
});


// VIDEO PAGE
$("ul.vid-thumbs").ytplaylist({addThumbs:true, autoPlay: false, holderId: 'video-container'});


// PAGE PAGE
$("ul.page-vid-thumbs").ytplaylist({addThumbs:false, autoPlay: false, holderId: 'page-video-container'});






/*
// http://tutorialzine.com/2010/07/youtube-api-custom-player-jquery-css/
	$('#player').youTubeEmbed('http://www.youtube.com/watch?v=u1zgFlCw8Aw');

	
// YOUTUBE EMBED - You can alternatively pass an object:
/*
		$('#player').youTubeEmbed({
			video			: 'http://www.youtube.com/watch?v=u1zgFlCw8Aw',
			width			: 600, 		// Height is calculated automatically
			progressBar	: false		// Hide the progress bar
		});

	*/





//// ACCORDION ////
// dependencies: jquery, jquery-ui-1.8.1.custom.min.js, 
$("#fb-accordion").accordion({ 
	header: "h2",
	collapsible: false, // if none should be open
	autoHeight: true,
	navigation: false,
	active: false, 
	alwaysOpen: false, 
	animated: true
});

// TOGGLA FB divvar. Display:none i style.css
$(".but-facebook").click(function () {
	$("div.facebookwrap").slideToggle("slow");
});






	});
})(jQuery);
// JQUERY WRAPPER CLOSE








// BIG G ANAL KONTO 2011
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-27135893-1']);
_gaq.push(['_setDomainName', '.extrem.com']);
_gaq.push(['_trackPageview']);

(function() {
  var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

/*
(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=152348638142899";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
*/


window.fbAsyncInit = function() {
  FB.init({
    appId      : '168540723160627',
    status     : true, 
    cookie     : true,
    xfbml      : true,
    oauth      : true,
  });
};

// FACEBOOK CONNECT STUFF OBS DIV "fb-root" http://developers.facebook.com/docs/reference/plugins/like/
(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) {return;}
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=168540723160627";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));


/*
https://developers.facebook.com/docs/opengraph/tutorial/
http://developers.facebook.com/tools/debug/og/object?q=extrem.com
// FACEBOOK OPEN GRAPH STUFF
{
   "url": "http://extrem.com/",
   "type": "website",
   "title": "Extrem skidor i \u00c5re",
   "locale": {
      "locale": "sv_se"
   },
   "image": [
      {
         "url": "http://extrem.com/favicon.ico"
      }
   ],
   "description": "Extrem is a ski production facility at Scandinavias greatest ski resort.",
   "updated_time": "2012-02-11T11:00:01+0000",
   "id": "429164619961",
   "application": {
      "id": "168540723160627",
      "name": "Extrem skis & snowboards",
      "url": "http://www.facebook.com/apps/application.php?id=168540723160627"
   }
}
*/
