BROWSER = new Object();
BROWSER.isOpera = navigator.userAgent.indexOf("Opera") > -1;
BROWSER.isIE    = navigator.userAgent.indexOf("MSIE") > 1 && !BROWSER.isOpera; 
BROWSER.isMoz   = navigator.userAgent.indexOf("Mozilla/5.") == 0 && !BROWSER.isOpera;

if (typeof($) != "function") $ = function(ID){ return document.getElementById(ID); }

function redirect(id) {
   alert("This link works only in front-end site!")
}

function popupimg(img) {
    var d = new Date()
    var ID = d.getDate()+""+d.getMonth()+1+""+d.getFullYear()+""+d.getHours()+""+d.getMinutes()+""+d.getSeconds();

    var loc = "/enlarge.php?src="+img;
	var win = window.open(loc, "_new"+ID,"toolbar=yes,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=200,height=200");
	win.location.href = loc;
	win.focus();
}

/* highlist elements onmouse over event
 */
function highlight(groupElements, classOver) {
   var i, j, Obj, groupObjects = [];
   for(j=1; j<100; j++) {
   	   for(i in groupElements) {
   	   	   Obj = $(groupElements[i]+j);
           if (Obj) {
               Obj.ind = j; 
               groupObjects[groupObjects.length] = Obj;
           }
       }
   }
   
   for(i in groupObjects) {
      Obj = groupObjects[i];
      Obj.classDefault = Obj.className;
      Obj.classOver = classOver;
      Obj.groupObjects = groupObjects;
      
      Obj.onmouseover = function() {
      	  this.className = this.classOver;
      	  for(var i in this.groupObjects){
      	      var Obj = this.groupObjects[i]; 
      	  	  if (Obj.ind == this.ind) Obj.className = Obj.classOver;
      	  }
      }
      Obj.onmouseout = function() {
      	  this.className = this.classDefault;
      	  for(var i in this.groupObjects){
      	  	  var Obj = this.groupObjects[i];
      	  	  if (Obj.ind == this.ind) Obj.className = Obj.classDefault;
      	  }
      }
   }
}

function openLink(link) {
   location.href = link;
}

function AjaxSubmitVar(form_id, value, err, server_url, div_id, type )
{
	$.ajax({
      type: "POST",
      url: server_url,
	  data: $('#'+form_id).serialize() + "&country=" + value  + "&error=" + err + "&type=" + type,
      success: function(msg) 
      {
		$('#'+div_id).html(msg)
        .fadeIn(500);
      }
     });
    return false;
}

function formSubmit(id)
{
	document.getElementById(id).submit();
}

function engageFancy(id){
    $('a#'+id).trigger('click');
}

var minF=12;
var maxF=13;
function increaseFontSize() {
   var p = document.getElementsByTagName('p');

   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 12;
      }
      if(s!=maxF) {
         s += 1;
      }
      p[i].style.fontSize = s+"px"
   }
}
function decreaseFontSize() {
   var p = document.getElementsByTagName('p');

   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 12;
      }
      if(s!=minF) {
         s -= 1;
      }
      p[i].style.fontSize = s+"px"
   }   
}

/*function slideShow() {
 
    //Set the opacity of all images to 0
    $('#gallery a').css({opacity: 0.0});
     
    //Get the first image and display it (set it to full opacity)
    $('#gallery a:first').css({opacity: 1.0});
     
    //Set the caption background to semi-transparent
    //$('#gallery .caption').css({opacity: 0.7});
 
    //Resize the width of the caption according to the image width
    $('#gallery .caption').css({width: $('#gallery a').find('img').css('width')});
     
    //Get the caption of the first image from REL attribute and display it
    $('#gallery .content').html($('#gallery a:first').find('img').attr('rel'))
    .animate({opacity: 1}, 400);
     
    //Call the gallery function to run the slideshow, 6000 = change to next image after 6 seconds
    setInterval("gallery('next')",6000);
     
}
 
function gallery(direction1) {
     
    //if no IMGs have the show class, grab the first image
    var current = ($('#gallery a.show') ?  $('#gallery a.show') : $('#gallery a:first'));
 
    //Get next image, if it reached the end of the slideshow, rotate it back to the first image
    if(direction1 == 'next')
		var next = ((current.next().length) ? ((current.next().hasClass('caption'))? $('#gallery a:first') :current.next()) : $('#gallery a:first'));  
    else
		var next = ((current.prev().length) ? ((current.prev().hasClass('caption'))? $('#gallery a:last') :current.prev()) : $('#gallery a:last'));
    //Get next image caption
    var caption = next.find('img').attr('rel');
     
    //Set the fade in effect for the next image, show class has higher z-index
    next.css({opacity: 0.0})
    .addClass('show')
    .animate({opacity: 1.0}, 1000);
 
    //Hide the current image
    current.animate({opacity: 0}, 1000)
    .removeClass('show');
     
    //Set the opacity to 0 and height to 1px
    //$('#gallery .caption').animate({opacity: 0.0}, { queue:false, duration:0 }).animate({height: '1px'}, { queue:true, duration:300 });
	//$('#gallery .caption').animate({height: '1px'}, { queue:true, duration:300 });
    $('#gallery .caption').css("height", "1"); 
	 
	 
    //Animate the caption, opacity to 0.7 and heigth to 100px, a slide up effect
   // $('#gallery .caption').animate({opacity: 0.6},100 ).animate({height: '85px'},500 );
	$('#gallery .caption').animate({height: '85px'},500 );
     
    //Display the content
    $('#gallery .content').html(caption);
         
}
*/

function slideShow() {
 
    //Set the opacity of all images to 0
    $('#gallery a').css({opacity: 0.0});
     
    //Get the first image and display it (set it to full opacity)
    $('#gallery a:first').css({opacity: 1.0});
     
    //Set the caption background to semi-transparent
    //$('#gallery .caption').css({opacity: 0.7});
 
    //Resize the width of the caption according to the image width
    $('#gallery .caption').css({width: $('#gallery a').find('img').css('width')});
     
    //Get the caption of the first image from REL attribute and display it
    $('#gallery .content').html($('#gallery a:first').find('img').attr('rel'))
    .animate({opacity: 1}, 400);
     
    //Call the gallery function to run the slideshow, 6000 = change to next image after 6 seconds
    setInterval('gallery()',6000);
     
}
 
function gallery() {
     
    //if no IMGs have the show class, grab the first image
    var current = ($('#gallery a.show') ?  $('#gallery a.show') : $('#gallery a:first'));
 
    //Get next image, if it reached the end of the slideshow, rotate it back to the first image
    var next = ((current.next().length) ? ((current.next().hasClass('caption'))? $('#gallery a:first') :current.next()) : $('#gallery a:first'));  
     
    //Get next image caption
    var caption = next.find('img').attr('rel');
     
    //Set the fade in effect for the next image, show class has higher z-index
    next.css({opacity: 0.0})
    .addClass('show')
    .animate({opacity: 1.0}, 1000);
 
    //Hide the current image
    current.animate({opacity: 0}, 1000)
    .removeClass('show');
     
    //Set the opacity to 0 and height to 1px
    //$('#gallery .caption').animate({opacity: 0.0}, { queue:false, duration:0 }).animate({height: '1px'}, { queue:true, duration:300 });
	//$('#gallery .caption').animate({height: '1px'}, { queue:true, duration:300 });
    $('#gallery .caption').css("height", "1"); 
	 
	 
    //Animate the caption, opacity to 0.7 and heigth to 100px, a slide up effect
   // $('#gallery .caption').animate({opacity: 0.6},100 ).animate({height: '85px'},500 );
	$('#gallery .caption').animate({height: '85px'},500 );
     
    //Display the content
    $('#gallery .content').html(caption);
         
}





/*function fancyPopup(l, w, h){
    var sep = l.href.match(/\?/) ? '&' : '?';
    if (!w) w = 600;
    if (!h){
        var h90 = $(window).height();
        h90 = Math.round(h90 * .8);
        h = h90; 
    }

    $.fancybox({
		'width'		    : w,
		'height'		: h,
		'href'			: l.href + sep + 'popupIframe=1',
		'type'			: 'iframe',
    });
    return false;
}
*/

$(document).ready(function() 
{
	$('.NextPic').click(function() 
	{
		gallery('next');
		return false;
	});
	$('.PrevPic').click(function() 
	{
		gallery('prev');
		return false;
	});
	 $('.PageGalleryMask').click(function() 
	{
		$('a.show').click();
		
		return false;
	});
	
});

