/* 
 * @see http://hoffmannkrzysztof.pl
 * @author Krzysztof Hoffmann <krzysztof.hoffmann@tro.pl>
 * @copyright 2010 (C)
 */
//$(document).ready(function()
//{

//$("div#txt").find("a").click(function(){
//if(loc !='informacjeprasowe')
//{
    // window.open($(this).attr("href"));
    // return false;
//}
//});
//});
try
{
tinyMCE.init({
		// General options
		mode : "textareas",
		theme : "advanced",
		convert_urls : false,
		relative_urls : false,
		extended_valid_elements : "div[*]",
		body_id : "txt",
		plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount,advlist,autosave",

		// Theme options
		theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
		theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,bullist,numlist,|,outdent,indent,blockquote,link,unlink,anchor,image,cleanup,help,code,forecolor,backcolor",
		theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,media,advhr,ltr,rtl,|,fullscreen",
		theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak,restoredraft",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true,

		// Example content CSS (should be your site CSS)
		content_css : "/public/styles/style.css",

		// Drop lists for link/image/media/template dialogs
		template_external_list_url : "lists/template_list.js",
		external_link_list_url : "lists/link_list.js",
		external_image_list_url : "lists/image_list.js",
		media_external_list_url : "lists/media_list.js",

		// Style formats
		style_formats : [
			{title : 'Bold text', inline : 'b'},
			{title : 'Red text', inline : 'span', styles : {color : '#ff0000'}},
			{title : 'Red header', block : 'h1', styles : {color : '#ff0000'}},
			{title : 'Example 1', inline : 'span', classes : 'example1'},
			{title : 'Example 2', inline : 'span', classes : 'example2'},
			{title : 'Table styles'},
			{title : 'Table row 1', selector : 'tr', classes : 'tablerow1'}
		],

		// Replace values for the template plugin
		template_replace_values : {
			username : "Some User",
			staffid : "991234"
		}
	});
}
catch(err){}

$(document).ready(function()
{

//$(".popup-img").attr("name", $(".popup-img").attr("href") );
//$(".popup-img").attr("href",'javascript://');

$(".popup-img").click(function(){
    //alert($(this).attr('href'));
    //alert($(this).attr('src'));
        $.modal('<img style="width:400px;margin:0;padding:0" src="'+$(this).attr('href')+'"/>', {
             containerCss:{
                     backgroundColor:"#fff",
                     borderColor:"black",
                     height:"80%",
                     padding:0,
                     width:400
             },
             overlayClose:true,
             opacity:80,
             position: ["5%",null],
             overlayCss: {backgroundColor:"#fff"}
     });
     return false;
});

});

function slideSwitch(div) {
    var $active = $(div+' div.active');

    if ( $active.length == 0 ) $active = $(div+' div:last');

    var $next =  $active.next().length ? $active.next()
        : $(div+' div:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

function slideSwitch_img(div) {
    var $active = $(div+' img.active');

    if ( $active.length == 0 ) $active = $(div+' img:last');

    var $next =  $active.next().length ? $active.next()
        : $(div+' img:first');

    pnr = $active.attr('id').split('-')[1];
    nr = $next.attr('id').split('-')[1];

    $('#slides #control ul').children().removeClass('active');
    $($('#slides #control ul').children()[nr]).addClass('active');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

function slideTo(nr, last) {
    var $active = $($('#slides img')[last]);

    //if ( $active.length == 0 ) $active = $(div+' img:last');

    var $next =  $($('#slides img')[nr]);

   var  pnr = $active.attr('id').split('-')[1];
   var  nr = $next.attr('id').split('-')[1];

    $('#slides #control ul').children().removeClass('active');
    $($('#slides #control ul').children()[nr]).addClass('active');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

function show_news(div) {
if(noreload || $('#'+div).parent().hasClass('open')) return;
	//zamykanie otwartego
	var open = $('.open');
	var d = $('#'+div).parent();
	open.animate({height:31},500,function(){open.removeClass('open');});
	d.animate({height:138},500,function(){d.addClass('open');});


}

(function ($) {
$.fn.vAlign = function() {
	return this.each(function(i){
	var h = $(this).height();
	var oh = $(this).outerHeight();
	var mt = (h + (oh - h)) / 2;
	$(this).css("margin-top", "-" + mt + "px");
	$(this).css("top", "50%");
	$(this).css("position", "absolute");
	});
};
})(jQuery);

(function ($) {
$.fn.hAlign = function() {
	return this.each(function(i){
	var w = $(this).width();
	var ow = $(this).outerWidth();
	var ml = (w + (ow - w)) / 2;
	$(this).css("margin-left", "-" + ml + "px");
	$(this).css("left", "50%");
	$(this).css("position", "absolute");
	});
};
})(jQuery);

(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery);


function align() {
  $('#field div img').vAlign();
$('#field div img').hAlign();
$('#field div img').show();
}

var noreload = false;

$(document).ready(function() {
    /*    $('ul.sf-menu').superfish({
            delay:       500,                            // one second delay on mouseout
            animation:   {opacity:'show',height:'show'},  // fade-in and slide-down animation
            speed:       'fast',                          // faster animation speed
            autoArrows:  false,                           // disable generation of arrow mark-up
            dropShadows: false                            // disable drop shadows
        });
*/
	//$('#slid li').first().addClass('active');
		$('#news .hide').show();

$('a.more').click(function(){
	noreload = true;
});

//$('#field div img').vAlign();
//$('#field div img').hAlign();

	    setInterval( "slideSwitch('#slid')", 5000 );

$('#field div img').hide();
	    setInterval( "slideSwitch('#field')", 5000 );
	    setTimeout( "align()", 5100 );

	    setInterval( "slideSwitch_img('#slides')", 10000 );


	    $('#slides #control ul a').click(function(){
		nr = $(this).text()-1;
		last = (nr-1 >= 0)?(nr-1):2;
		slideTo(nr,last);
	    });

jQuery.preLoadImages("/public/img/prasa-o.png",
			"/public/img/relacje-inwestorskie-o.png",
			"/public/img/o-spolce-o.png",
			"/public/img/kariera-o.png",
			"/public/img/kontakt-o.png",
		        "/public/img/dzialalnosc-o.png");

$('#search form').submit(function(){

if($('#sinput').val().length < 3) {
	 $("#msg").text("Wyszukiwana fraza musi być dłuższa niż 3 znaki.").modal({
	opacity:80,
        height:'auto',
        minHeight:0,
        overlayClose:true,
	overlayCss: {backgroundColor:"#fff"}
          
	 
});
return false;
}

});

        $("#left-menu a.lista").click(function(){

          var  that = $(this);

           if( $(this).hasClass('see') )
                {
                     $(this).removeClass('see');
                     $("img.strzalkaMenu",this).attr('src','/public/images/strz-dol.gif');
		   //  console.log("opening");
                     while($(that).next().hasClass('hiddenMenu') && $(that).next().hasClass('podMenu'))
                     {
			    // console.log(that);
                          $(that).next().css("cssText",'display:none !important');
                          that = $(that).next();
                     }


                }else
                     {
                          $(this).addClass('see');
                          $("img.strzalkaMenu",this).attr('src','/public/images/strz-gora.gif');
			 // console.log("closing");
                          while($(that).next().hasClass('hiddenMenu') && $(that).next().hasClass('podMenu'))
                          {
				 // console.log(that);
                               $(that).next().css("cssText",'display:block !important');
                               that = $(that).next();
                          }
                     }

           

        });
if($("#msg").text()!='')
        $("#msg").modal({
	opacity:80,
        height:'auto',
        minHeight:0,
        overlayClose:true,
	overlayCss: {backgroundColor:"#fff"}
          });


     $("#siedziba_img").tooltip({
    bodyHandler: function() {
        return "Siedziba TRO MEDIA SA";
    },
    showURL: false
});

$("#img_news").tooltip({
    bodyHandler: function() {
        return "Zapisz się do naszego newslettera<br/>i otrzymuj bieżące informacje z życia Spółki!";
    },
    showURL: false
});

$(".rb-link").tooltip({
    bodyHandler: function() {
        return $(this).attr('rel');
    },
    showURL: false
});

$("#mapka").click(function(){


     $.modal('<iframe width=516 height=316 src="/map.html">', {
	containerCss:{
		backgroundColor:"#fff",
		borderColor:"#0063dc",
		height:280,
		padding:0,
		width:520
	},
	overlayClose:true,
        opacity:80,
        position: ["25%",null],
        overlayCss: {backgroundColor:"#fff"}
});

});


/*$(".media_head").click(function(){

   var that = $(this).next();

   $(that).modal({
	opacity:80,
        minWidth:800,
        minHeight:'640px !important',
        overlayClose:true,
	overlayCss: {backgroundColor:"#fff"}
          });

          return false;

});*/


    }); 


$(document).ready(function() {

	$(".tab_content").hide(); //Hide all content
	$("ul.tabs li:first").addClass("active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content

	//On Click Event
	$("ul.tabs li").click(function() {

		if ($(this).find("a").attr("href") != 'javascript://')
		{
		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).show(); //Fade in the active ID content
		return false;
		}
	});

});

