// 
jQuery(window).load(function()
{
  //iterate the images that have the imageFitBox class set up
  $('.listStyleBox img.imageFitBox').each(function()
  {
    //check if image height exceeds the maximal height of box
    if($(this).height() > 165)
    {
      //if so - limit only the height to maximal height
      $(this).css('height','165px');
    }
    //IMPORTANT! after setting up the height, check the width
    if($(this).width() > 220)
    {
      //reset the height...
      $(this).css('height','');
      //.. and apply width constraint
      $(this).css('width','220px');
    }
    // you can also set up the margins of image, to center it inside the box
    //$(this).css('margin-left',( ( 220-$(this).width() )/2)+'px');
    $(this).css('margin-top',( ( 165-$(this).height() )/2)+'px');
  });
  $('.filmStyleListing img.imageFitBox').each(function()
  {
    //check if image height exceeds the maximal height of box
    if($(this).height() > 110)
    {
      //if so - limit only the height to maximal height
      $(this).css('height','110px');
    }
    //IMPORTANT! after setting up the height, check the width
    if($(this).width() > 110)
    {
      //reset the height...
      $(this).css('height','');
      //.. and apply width constraint
      $(this).css('width','110px');
    }
    // you can also set up the margins of image, to center it inside the box
    //$(this).css('margin-left',( ( 110-$(this).width() )/2)+'px');
    $(this).css('margin-top',( ( 110-$(this).height() )/2)+'px');
  });
});
//

// topLink
jQuery.fn.topLink = function(settings) {
	settings = jQuery.extend({
		min: 1,
		fadeSpeed: 200,
		ieOffset: 50
	}, settings);
	return this.each(function() {
		//listen for scroll
		var el = $(this);
		el.css('display','none'); //in case the user forgot
		$(window).scroll(function() {
			if(!jQuery.support.hrefNormalized) {
				el.css({
					'position': 'absolute',
					'top': $(window).scrollTop() + $(window).height() - settings.ieOffset
				});
			}
			if($(window).scrollTop() >= settings.min)
			{
				el.fadeIn(settings.fadeSpeed);
			}
			else
			{
				el.fadeOut(settings.fadeSpeed);
			}
		});
	});
};

jQuery(document).ready(function() {
	$('#top-link').topLink({
		min: 400,
		fadeSpeed: 500
	});
	//smoothscroll
	$('#top-link').click(function(e) {
		e.preventDefault();
		$.scrollTo(0,300);
	});
});
// end

// modal
jQuery(document).ready(function() {	
	//select all the a tag with name equal to modal
	$('a[name=modal]').click(function(e) {
		//Cancel the link behavior
		e.preventDefault();
		
		//Get the A tag
		var id = $(this).attr('href');
	
		//Get the screen height and width
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();
	
		//Set heigth and width to mask to fill up the whole screen
		$('#mask').css({'width':maskWidth,'height':maskHeight});
		
		//transition effect		
		$('#mask').fadeTo("fast",0.8);
		$('#mask').fadeIn(250);
	
		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();
              
		//Set the popup window to center
		$(id).css('top', winH/2-$(id).height()/2);
		$(id).css('left', winW/2-$(id).width()/2);
	
		//transition effect
		$(id).fadeIn(250); 
	
	});
	
	//if close button is clicked
	$('.window .close').click(function (e) {
		//Cancel the link behavior
		e.preventDefault();
		
		// custom close/stop gameplay in iframe
		reloadblank();
		
		$('#mask').fadeOut(250);
		$('.window').fadeOut(250);
		//$('#mask').hide();
		//$('.window').hide();
	});		
	
	//if mask is clicked
	$('#mask').click(function () {
		
		// custom close/stop gameplay in iframe
		reloadblank();
		
		$('#mask').fadeOut(250);
		$('.window').fadeOut(250);
		//$(this).hide();
		//$('.window').hide();
	});		
});
// end

// round corners
$(function(){
	/*$('.sc_productsMenu span').corner({
		tl: { radius: 10 },
		tr: { radius: 10 },
		bl: { radius: 10 },
		br: { radius: 10 },
        antiAlias: true,
		autoPad: false,
		validTags: ["div"]
	});
	$('#MenuStyle a').corner({
		tl: { radius: 12 },
		tr: { radius: 12 },
		bl: { radius: 12 },
		br: { radius: 12 },
        antiAlias: true,
		autoPad: false,
		validTags: ["div"]
	});*/
	$('ul.sc_bannerMenu span').corner("10px; cc:#fff");
	$('ul.sc_productsMenu span').corner("10px; cc:#fff");
	$('#bannerMenu').corner("15px; cc:#ca2828; top round");
	$('.subMenuWhitePanel').corner("20px; cc:#f6f6f6");
	$('.subMenuPreviewInner').corner("10px; cc:#f8a350");
	$('#MenuStyle a').corner("12px; cc:#f8a350");
	$('.contentArea').corner("15px; cc:#ca2828");
});
//
