jQuery(function( $ ){
	var sizes = getWindowSizes();	
	
	var height_body=sizes[1];	
	var min_height_body=$('.all').height();	
	if (height_body<min_height_body) {$('body').height(min_height_body);} else {$('body').height(height_body);}

	$('.lightbox').lightBox();
	
	var el = $("ul > .scroll-interval").length;
	$('ul.blocks').css('width', $('ul.blocks li').outerWidth()*el+'px');

});

function getWindowSizes() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  //window.alert( 'Width = ' + myWidth );
  //window.alert( 'Height = ' + myHeight );
  return [myWidth,myHeight];
}

function galItemClickInit() {
	RUZEE.ShadedBorder.create({ corner: 40, border: 1 }).render($('.gallery_video'));
	
	$('.gallery_video_paginator .item').removeClass('active');
	$('.gallery_video_paginator .item_01').addClass('active');
	
	var videoNumber=$('.gallery_video').attr('id');
	setVideo(VideoVimeo[videoNumber+'_0'], 560, 315);
	var Paginator=0;
	var oldPaginator=0;
	
	$('.gallery_video_paginator .item').click(function(){
			$('.gallery_video_paginator .item').removeClass('active');
			var items = $($(this).parent()).children('.gallery_video_paginator .item');
			$(this).addClass('active');
			Paginator=getIndexOf(items,this);
		if (oldPaginator!=Paginator) {
			var nVideo=videoNumber + '_' + Paginator;
			setVideo(VideoVimeo[nVideo], 560, 315);
			oldPaginator=Paginator;
		}
	});
}

var VideoVimeo = new Array();
VideoVimeo ['video_pb_0'] = '22648829';

function getIndexOf(arr,obj) {
	for (var i=0;i<arr.length;i++) {
		if (arr[i]==obj) return i;
	}
	return -1;
}

function setVideo(id, w, h) {
	$('.gallery_show_play').empty();
	//$('.gallery_show_play').html(generateVideoHTML(id, w, h));
	generateVideoHTML(id, w, h);
}

function generateVideoHTML(id,w,h) {

 //video for BR settings
 var videoWidth=w;
 var videoHeight=h;
 var video_id = id;
 var moogaloop = false;
 var swf_id = 'moogaloop';
  
  var flashvars = {
  clip_id: video_id,
  show_portrait: 1,
  show_byline: 1,
  show_title: 1,
  js_api: 1, // required in order to use the Javascript API
  js_onLoad: 'vimeo_player_loaded', // moogaloop will call this JS function when it's done loading (optional)
  js_swf_id: 'moogaloop' // this will be passed into all event methods so you can keep track of multiple moogaloops (optional)
     };
 
  var params = {
   allowscriptaccess: 'always',
   allowfullscreen: 'true'
  };
  var attributes = {};

  // For more SWFObject documentation visit: http://code.google.com/p/swfobject/wiki/documentation
  swfobject.embedSWF("http://vimeo.com/moogaloop.swf", "gallery_show_play", w, h, "9.0.0","expressInstall.swf", flashvars, params, attributes);
 
 
}

  function playVideo() {
   moogaloop = document.getElementById("gallery_show_play");

   if(typeof moogaloop.api_play == 'function') {
    moogaloop.api_play()
   } else {

	setTimeout(playVideo,1000);
   } 
  }
  function vimeo_player_loaded(swf_id) {
	playVideo();
  }
  
  function stopVideo(){
	moogaloop = document.getElementById("gallery_show_play");
	moogaloop.api_pause();
	$(moogaloop).empty();
  }
  
  
