$(document).ready(function() {
	$(".videos-container").width($(".videos-container").children().size()*162+"px")
	
	$('img').bind("contextmenu",function(e){
        return false;
    });



	if($.browser.msie && $.browser.version=="6.0")
	{
		DD_belatedPNG.fix('img');
		//DD_roundies.addRule('.rounds3', '3px');
	}
	
	$('.c20').corner('20px');
	$('.c5').corner('5px');
   
    if($(".btn").length>0)
	{
		$(".btn").hover(function() {
			  $(this).stop().animate({ backgroundColor: "#53461c"}, 600);},
		   function() {
			  $(this).stop().animate({ backgroundColor: "#262626" }, 600);
		});
	}
	  
	$("ul.blockeasing li.main").mouseover(function(){ 
		$(this).children('.subnav').children().show();
		  licount = $(this).children(".subnav").children('li').size();
		  blockheight = licount*25;
		  $(this).children('.subnav').stop().animate({height: blockheight+'px', opacity:'1'},{queue:false, duration:200});
	});
	
	$("ul.blockeasing li.hassub").mouseover(function(){ 
		$(this).children('.subnav').children().show();
		  licount = $(this).children(".subnav").children('li').size();
		  blockheight = licount*25;
		  $(this).children('.subnav').stop().animate({height: blockheight+'px', opacity:'1'},{queue:false, duration:200});
	});


	$("ul.blockeasing li.hassub").mouseout(function(){
		
		  $(this).children('.subnav').stop().animate({height:'0px', opacity:'0'},{queue:false, duration:200});
		  $(this).children('.subnav').children().hide();
	});
	
	$("ul.blockeasing li.main").mouseout(function(){
		
		  $(this).children('.subnav').stop().animate({height:'0px', opacity:'0'},{queue:false, duration:200});
		  $(this).children('.subnav').children().hide();
		  
	});
	
	if($(".galdiv").length>0) equalHeight($(".galdiv"));

	
	if($('.galimg').length>0)
	{
		$().piroBox_ext({
		piro_speed : 700,
		bg_alpha : 1,
		piro_scroll : true // pirobox always positioned at the center of the page
	});
	}


	
	$("ul.submenu:not('.open')").hide();
    $("ul.submenu2:not('.open')").hide();
	
//	$(".portmenu li.toggleSubMenu > a").mouseenter( function (event){
//		$(".portmenu > li").removeClass("active");
//		$(this).parent().addClass("active");
//		if ($(this).next("ul.submenu:visible").length != 0){
//			return true;
//		}
//		else{
//			$(".portmenu li.active").removeClass("active")
//			$(".portmenu ul.submenu").slideUp("normal", function () {  } );
//			$(this).parent().addClass("active")
//			$(this).next("ul.submenu").slideDown("normal", function () {  } );
//		}
//		
//	});
//
	$("li.toggleSubMenu2 > a").click( function (event){

		$("li.toggleSubMenu2").removeClass("active");
		$(this).parent().addClass("active");

		if ($(this).next("ul.submenu2:visible").length != 0){
			return false;
		}else{
			$("li.toggleSubMenu2 li.active").removeClass("active")
			$("li.toggleSubMenu2 ul.submenu2").slideUp("normal", function () {  } );

			$(this).addClass("active");
			$(this).next("ul.submenu2").slideDown("normal", function () {  } );
		}
		return false;
	}); 
	 
	
	
	
	/*
	if($('#topthumbs li.fade').length>0)
	{
		$('#topthumbs li.fade').each(function() {
			var _id = $(this).attr('id');
			setInterval(function(){
					slideSwitch(_id);              
				}, 5000);
	
		});
	}
	*/
	
	
	
	PlayerImage();
	
	
	$(".playerDiv").click(function()
	{
		var _thumb =$(this).attr("rel");
		var _bvideo =$(this).attr("id");
		
			var _dbox = document.createElement("div");
			var _pbox = document.createElement("div");
			_dbox.id='mydialog';
			_pbox.id='pplid';
			$(_dbox).append(_pbox);
			document.body.appendChild(_dbox);
			
			$(_dbox).dialog({
			show: 'scale', 
			hide: 'scale',
			modal:true,
			minWidth:480,
			minHeight:480,
			beforeClose: function(event, ui) {$(_dbox).find('#pplid').remove(); },
			close:function(){ $(this).dialog('destroy');  $(_dbox).remove();  }});
			
			viewPlayer_Jw('pplid',_thumb,_bvideo);
		
		return false;
	});
	
});

function viewPlayer_Jw(place,thumb,bideo)
{
	jwplayer(place).setup({
		flashplayer: "/upload/player.swf",
		file: bideo,
		image:thumb,
		height: 450,
		width: 450,
		skin:'/upload/glow.zip',
		stretching:'fill'
	});
}

function PlayerImage()
{
   $(".opacity").each( function(i,e)
   {
	
	var _divIsNew = document.createElement("div");
	
	var _position = $(e).position();
	var _newImage = new Image();
	_divIsNew.appendChild(_newImage);
	
	_newImage.src = "/images/player.png";
	_newImage.onload = function()
	{
		var _positions  =$(e).position();
		var _width  =$(e).width();
		
		var _height  =$(e).height();
		
		$(_divIsNew).css({
						 width:this.width,height:this.height,position:"absolute",top:_positions.top+30,left:_position.left+53,'z-index':this.style.zIndex+5});
		$(_divIsNew).insertBefore($(e));
		
	}
	
	});
}

function slideSwitch(param) {
    var $active = $('#'+param+' IMG.active');

    if ( $active.length == 0 ) $active = $('#'+param+' IMG:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#'+param+' IMG:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 2000, function() {
            $active.removeClass('active last-active');
        });
}


function equalHeight(group) {
	var tallest = 0;
	group.each(function() {
		var thisHeight = $(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	group.height(tallest);
}
