var fade_time = 300;
var li_marg = 20;
var dl = 0;
var lngListClickC = 0;
var maxV;
var active_movie = 0;
var storesList;
var out;
var flash_f;
var map;
var stores_distance = [];
var stores_latlang = [];
var temp_dist;
var stores_count = 0;
var stores_length;
var stores_2_display = 1;
var arr = [];
var t;
var filmTime;
var filmDuration;
var video;
var wishbagC = 0;
var wishLength;
var bagLength;
var itemLength;
var storeCloud = 0;
var heritageActive = 0;
var heritageCount;
var activeColumnCount;
var blank_share;
var thbDelta;
var locatorAcolumns = 0;
var activeColumnCount = 0;
var activeScribeSubTab = 0;
var heritageXipad;
var heritageBlock = 0;
var emailReg = /^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+$/;
var newsArray = {
	'newsletter_input':emailReg
};
var scribeSubTabsLength = 0;
var filmW = 941;
var scribePage = false;
//if($('.scribeAppHolder').length>0){

if ($('.scribeAppHolder').length>0) {
	filmW = 745;
	scribePage = true;
}
var hasError = new Array();
function roundVal(val) {
    var dec = 2;
    var result = Math.round(val * Math.pow(10, dec)) / Math.pow(10, dec);
    return result;
}
function _progressTimeout() {
    setTimeout(function () {
        _updateProgress();
    }, 200);
}
function _updateProgress() {
    filmTime = video.currentTime;
	filmDuration = video.duration;
    var percent = filmTime / filmDuration * 100;
	$('#film_timeline .ui-slider-handle').css('left', percent + '%');
    $('#past').css("width", roundVal(video.buffered / filmDuration * 100) + "%");
    _progressTimeout();
}
//var active_movie = 0;
String.prototype.pad = function (l, s) {
    return (l -= this.length) > 0
        ? (s = new Array(Math.ceil(l / s.length) + 1).join(s)).substr(0, s.length) + this + s.substr(0, l - s.length)
        : this;
};
function wishBagSlide(_this) {
    var _this = _this;
	
    var thisid = _this.attr('id');
    itemLength = wishLength;
    if (thisid === 'bagStatus') {
        itemLength = bagLength;
    }
    if (wishbagC === 0) {
        wishbagC = 1;
        $('#'+thisid+'C').children('.wishbag_container').animate({ 'top': '0px' }, fade_time, function () {
            $('body').bind('click', function (e) {
                var target = $(e.target);
                $('.wishbag_container').animate({ 'top': itemLength * (-103) - 70 }, fade_time, function () {
                });
            });
        });
        $('body').unbind('click');
    }
    else {
        $('.wishbag_container').animate({ 'top': itemLength * (-103) - 70 }, fade_time);
        wishbagC = 0;
        wishBagSlide(_this);
    }
    $('.wishbag_container').click(function () {
        return false;
    });
}
function loadJsonLatLng() {
  //  $.getJSON('site/js/stores1.json', function (data) {
        storesList = data = testJSON;
        $.each(storesList, function (k1, v1) {
            $.each(v1, function (k2, v2) {
                $.each(v2, function (k3, v3) {
                    $.each(v3, function (k4, v4) {
                        stores_latlang.push([v4.lat, v4.lng, k4, v4.id]);
                    });
                });
            });
        });
        stores_length = stores_latlang.length;
  //  });
}
function storeLocatorSetup() {
	

    //$.getJSON('site/js/stores1.json', function (data) {
    
        storesList = data = testJSON;

        $.each(data, function (k, v) {
            $('#continent ul').append('<li><span class="tl"></span><span class="tr"></span><span class="bl"></span><span class="br"></span>' + $.trim(k) + '</li>');
        });
        $('#continent ul li').live('click', function () {
            storeLocatorClick('country', 'continent', $(this));
        });
        $('#country ul li').live('click', function () {
            storeLocatorClick('city', 'country', $(this));
        });
        $('#city ul li').live('click', function () {
            storeLocatorClick('store', 'city', $(this));
        });
	/*	
    //});
    */
	
	
}
function storeLocatorClick(columnName, columnName2, _this) {
	var sameColumn = _this.siblings('li').hasClass('act');
	activeColumnCount = $('.act').length;
    $('#' + columnName2 + ' ul li').removeClass();
    _this.addClass('act');
    var countryList = '';
    var actCont = $('#continent ul li.act').text();
    var actCountry = $('#country ul li.act').text();
    var actCity = $('#city ul li.act').text();
    if (columnName === 'country') {
        if(activeColumnCount>1)
		{
			$('#city,#store').fadeOut(fade_time);
			cloudClean('store');
			cloudClean('city');
		}
		$.each(storesList[actCont], function (k, v) {
            countryList += '<li><span class="tl"></span><span class="tr"></span><span class="bl"></span><span class="br"></span>' + $.trim(k) + '</li>';
        });
    }
    if (columnName === 'city') {
        $.each(storesList[actCont][actCountry], function (k, v) {
            countryList += '<li><span class="tl"></span><span class="tr"></span><span class="bl"></span><span class="br"></span>' + $.trim(k) + '</li>';
        });
        $('#city').next('div').fadeOut(fade_time);
        cloudClean('country');
        if (storeCloud === 1) {
            cloudClean('city');
        }
		if(activeColumnCount>1)
		{
			cloudClean('store');
		}
    }
    if (columnName === 'store' ) {
        $.each(storesList[actCont][actCountry][actCity], function (k, v) {
            countryList += '<li><span class="tl"></span><span class="tr"></span><span class="bl"></span><span class="br"></span><a href="' + baseHref + 'store-locator/store.html?id=' + v.id + '">' + $.trim(k) + '</a></li>';
        });
        cloudClean('city');
    }
    else {
   }
    $('#' + columnName + ' ul').html(countryList);
	if(sameColumn===false){
		$('#' + columnName + '').fadeIn(fade_time, function () {
			$('#' + columnName + ' .locator_cloud').css('display', 'block').fadeTo(0, 0).animate({ 'top': '0px', 'opacity': '1' }, fade_time, function () {
			});
		});
	}
	if(activeColumnCount>1&&columnName==='country'){
		
		$('#'+columnName+' .locator_cloud').animate({ 'top': '0px', 'opacity': '1' }, fade_time, function () {});
	}
	if(activeColumnCount>1&&columnName==='city'){
	
		if(activeColumnCount!==2){
			$('#'+columnName+' .locator_cloud').animate({ 'top': '0px', 'opacity': '1' }, fade_time, function () {});
		}
	}
}
function cloudClean(columnName) {
    var top = -30;
    if (isAppleDevice===true) {
        top = '0';
    }
    $('#' + columnName + ' .locator_cloud').animate({ 'top': top, 'opacity': '0' }, fade_time, function () {    });
}
function sortStore() {
    $.each(stores_distance, function (k, v) {
        if (v !== undefined) {
            arr.push([k, v]);
        }
    });
    arr.sort(cmp);
    nearestStoreDisplay();
}
function nearestStoreDisplay() {
    var nearestStoresHtml = '';
    var it = 0;
    var i = 0;
	if(arr.length>0){
		for (i = 0; i < arr.length; i++) {
			for (j = 0; j < stores_latlang.length; j++) {
				if (stores_latlang[j][3] == arr[i][0]) {
					nearestStoresHtml += '<li><span><a href="' + baseHref + 'store-locator/store.html?id=' + stores_latlang[j][3] + '">' + stores_latlang[j][2] + '</a></span></li>';
				}
			}
		}
	}
	else{
		nearestStoresHtml += '<li><span>No Stores Found</span></li>';
	}
    $('#ipad_store_circles').fadeOut(fade_time / 2, function () {
        var columnName = 'ipad_store';
        $('#ipad_store ul').html(nearestStoresHtml);
        $('#' + columnName + '').fadeIn(fade_time, function () {
            $('#' + columnName + ' .locator_cloud').css('display', 'block').fadeTo(0, 0).animate({ 'top': '-40px', 'opacity': '1' }, fade_time, function () {
                out = setTimeout(function () { cloudClean(columnName) }, fade_time * 4);
            });
        });
    });
}
function nearestStore(lat, lng, lat_s, lng_s, s_id) {
    stores_count++;
    var directionsService = new google.maps.DirectionsService();
    var start = new google.maps.LatLng(lat, lng);
    var end = new google.maps.LatLng(lat_s, lng_s);
    var R = 6371;
    var dLat = toRad(lat_s - lat);
    var dLon = toRad(lng_s - lng);
    var dLat1 = toRad(lat);
    var dLat2 = toRad(lat_s);
    var a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
			Math.cos(dLat1) * Math.cos(dLat1) *
			Math.sin(dLon / 2) * Math.sin(dLon / 2);
    var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
    var d = R * c;
    if(d<500)
	{
		stores_distance[s_id] = parseInt(d);
    }
	if (stores_length === stores_count) {
        sortStore();
    }
}
function toRad(deg) {
    return deg * Math.PI / 180;
}
function sortNumber(a, b) {
    return b - a;
}
function cmp(a, b) {
    return a[1] - b[1];
}
function subMenuPos(th) {
    th.find('li').each(function (index) {
        dl += $(this).width() + li_marg;
    });
	var subMenuOffset = th.offset().left * (-1);
    var delta = th.width() - li_marg - dl;
	if((delta / 2) - 1>subMenuOffset){
		th.children('ul').css({ 'left': (delta / 2) - 1, 'width': dl+1 });    
	}
	else{
		subMenuOffset -= 3;
		th.children('ul').css({ 'left': subMenuOffset, 'width': dl+1 }); 
	}
	
}
function documentSize() {
    var xScroll, yScroll;
    if (window.innerHeight && window.scrollMaxY) {
        xScroll = window.innerWidth + window.scrollMaxX;
        yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }
    var windowWidth, windowHeight;
    if (self.innerHeight) {	// all except Explorer
        if (document.documentElement.clientWidth) {
            windowWidth = document.documentElement.clientWidth;
        } else {
            windowWidth = self.innerWidth;
        }
        windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }
    // for small pages with total height less then height of the viewport
    if (yScroll < windowHeight) {
        pageHeight = windowHeight;
    } else {
        pageHeight = yScroll;
    }
    // for small pages with total width less then width of the viewport
    if (xScroll < windowWidth) {
        pageWidth = xScroll;
    } else {
        pageWidth = windowWidth;
    }
    var viewportwidth;
    var viewportheight;

    // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight

    if (typeof window.innerWidth != 'undefined') {
        viewportwidth = window.innerWidth;
      viewportheight = window.innerHeight;
    }

    // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

    else if (typeof document.documentElement != 'undefined'
     && typeof document.documentElement.clientWidth !=
     'undefined' && document.documentElement.clientWidth != 0) {
        viewportwidth = document.documentElement.clientWidth;
       viewportheight = document.documentElement.clientHeight;
    }

    // older versions of IE

    else {
        viewportwidth = document.getElementsByTagName('body')[0].clientWidth;
       viewportheight = document.getElementsByTagName('body')[0].clientHeight;
    }
    return [pageWidth, pageHeight, viewportheight];
}
function placeGalleryImages(param) {
    var placeCount = 0;
    var total = 0;
    var img_margin = 16;
    var width_left;
    if (param === 'sl_img_s') {
        img_margin = 2;
    }
    $('.' + param + '').each(function () {
        $(this).children('.heritage_info_box').css('width', parseInt($(this).css('width')) - 32);
        if (placeCount > 0) {
            if (param === 'sl_img_b') {
                width_left = $('.' + param + ' .heritage_big_img').eq(placeCount - 2).width() + img_margin;
            }
            else {
                width_left = $('.' + param + ' img').eq(placeCount - 1).width() + img_margin;
            }
        }
        else {
            width_left = 0;
        }
        total = total + width_left;
        if(isAppleDevice===false){
			$('.' + param + '').eq(placeCount).css('left', total);
		}
		else{
			$('.' + param + '').eq(placeCount).attr('title', total);
		}
		placeCount++;
    });
}
function sliderSetup() {
    var pageWH = documentSize();
    var sliderW = pageWH[0] - 264 - 35;
    var bigPos = $('.sl_img_b').eq($('.sl_img_b').length - 1).css('left');
    bigPos = parseInt(bigPos, 10);
    bigPos += $('.sl_img_b').eq($('.sl_img_b').length - 1).width();   
    $("#slider").css('width', sliderW);
    $("#slider_bgd").css('width', sliderW + 35);
    //slider na heritage
    maxV = parseInt(bigPos - pageWH[0], 10);
    if (($('.sl_img_s').length - 1) * 156 > sliderW) {  
        $("#slider").slider({
            min: 0,
            max: maxV,
            slide: function (event, ui) {         
                $('#sl_thb').css({ 'left': -ui.value / 2.2 });
            },
            stop: function (event, ui) {
                var ratio = (ui.value / ($('.sl_img_s').length - 1 * 153 - sliderW));
                ratio = parseInt(ratio, 10);
                $('#sl_big').animate({ 'left': -ui.value }, fade_time);
            }
        });
    }
    else {
        $("#slider").slider({
            min: 0,
            max: maxV,
            stop: function (event, ui) {
                $('#sl_big').animate({ 'left': -ui.value }, fade_time);
                //$('#sl_big').css({ 'left': -ui.value });
                //console.log(ui.value);
            }
        });
    }
    //wykrycie czy galeria jest wieksza niz okno przegladarki
    if (pageWH[0] > bigPos) {
        $("#slider_bgd").css('display', 'none');
        $('#sl_big').animate({ 'left': 0 }, fade_time);
    }
    else {
        $("#slider_bgd").css('display', 'block');
    }
    if (pageWH[0] > $('.sl_img_s').length - 1 * 153) {
        $('#sl_thb').animate({ 'left': 0 }, fade_time);
    }
}
function productSliderSetup() {
	var pageWH = documentSize();
	var sliderW = pageWH[0] - 26;
	var bottom_list_width = $('#bottom_list ul li').length * 156;
	var top_list_width = $('#top_list ul li').length * 810;
	$('#bottom_list ul').css('width',bottom_list_width);
	$("#slider_bgd").css('width', sliderW);
	$("#product_slider").css('width', sliderW-35);
	$("#product_slider").slider({
			min: 0,
			max: bottom_list_width-pageWH[0],
			slide: function (event, ui) {
				$('#bottom_list ul').css({ 'left': -ui.value });
			}
	});
	 if (pageWH[0] > bottom_list_width) {
        $("#slider_bgd").css('display', 'none');
        $('#top_list').animate({ 'left': 0 }, fade_time);
       $('#bottom_list ul').animate({ 'left': 0 }, fade_time);
    }
    else {
        $("#slider_bgd").css('display', 'block');
    }
    if (pageWH[0] > bottom_list_width) {
       $('#bottom_list ul').animate({ 'left': 0 }, fade_time);
    }
	$('#top_list').css('width',top_list_width);
}

function sliderVsetup() {
    var pageWH = documentSize();
    //$('#film_mask').css({ 'width': pageWH[0] - 1020 });
    if ($('#movies_thb a').length > 8) {
        var maxVvalue = Math.ceil($('#movies_thb a').length / 2) * 99 - 384;
        $("#slider_v").slider({
            orientation: "vertical",
            min: 0,
            max: maxVvalue,
            value: maxVvalue,
            slide: function (event, ui) {
                $('#movies_thb').css({ 'top': ui.value - maxVvalue });
            }
        });
        $('#slider_v_bgd').removeClass('disable');
    }
}
function onOffPrevNextMovie() {
    if (active_movie === 0) {
        $('#prevMovie').fadeOut(fade_time);
        $('.prev_movie').css('visibility', 'hidden');
        $('#nextMovie').show();
        $('.next_movie').css('visibility', 'visible');
    }
    else {
        if (active_movie === $('#movies_container img').length - 1) {
            $('#nextMovie').fadeOut(fade_time);
            $('.next_movie').css('visibility', 'hidden');
			$('.prev_movie').css('visibility', 'visible');
            $('#prevMovie').show();
        }
        else {
            $('.prev_movie').css('visibility', 'visible');
            $('#prevMovie').show();
            $('#nextMovie').show();          
            $('.next_movie').css('visibility', 'visible');
        }
    }
}
function film_setup() {
	
    $('#movies_container .film').each(function (index) {
        if (index > 0) {
            $(this).css('left', index * 941);
        }
        else {
            $(this).css('left', index * 935);
        }
    });
    $('a.shareLink').attr('href', $('#movies_thb a').eq(0).attr('href'));
    if(scribePage===true){
		$('a.shareLink').attr('href',$('.film').eq(0).attr('site'));
	}
	//film_mask
}
function film_setup_scribe() {
	
    $('#scribeRight #movies_container .film').each(function (index) {
        if (index > 0) {
            $(this).css('left', index * 745);
        }
        else {
            $(this).css('left', index * 745);
        }
    });
    //$('a.shareLink').attr('href', $('#movies_thb a').eq(0).attr('href'));
    //if(scribePage===true){
		$('a.shareLink').attr('href',$('.film').eq(0).attr('site'));
	//}
	//film_mask
}

function changeMovie() {
	if($('#scribeRight').length>0){
		filmW = 745;
		scribePage = true;
	}
	else{
		filmW = 941;
	}
    var final_position = active_movie * filmW;
    if (isAppleDevice === false) {
        flash_f = document.getElementById('flash_player');
        if(flash_f){
			flash_f.stopVideo();
		}
        $('#movies_container, #film_desc_container').animate({ 'left': '-' + final_position }, fade_time, flashMoviePlay);
    }
    else {
		final_position = final_position*(-1);
		$('#movies_container, #film_desc_container').css({'-webkit-transition': 'left 0.3s linear','left':final_position});
		setTimeout(flashMoviePlay,fade_time);
    }
    $('a.shareLink').attr('href', $('#movies_thb a').eq(active_movie).attr('href'));
	if(scribePage===true){
		$('a.shareLink').attr('href',$('.film').eq(active_movie).attr('site'));
	}
    $('.ipadFilmPage #movies_container img').css('z-index',2999);
    onOffPrevNextMovie();
}

function activateFilmButtons() {
    $('.next_movie').click(nextMovie);
    $('#next_movie').click(nextMovie);
    $('.prev_movie').click(prevMovie);
    $('#prev_movie').click(prevMovie);
}
function prevMovie() {
    if (active_movie > 0) {
        active_movie -= 1;
        changeMovie();
    }
}
function nextMovie() {
    active_movie += 1;
    changeMovie();
}
function flashMoviePlay() {
    var img_movie_rel = $('.film').eq(active_movie).attr('rel');
	if (img_movie_rel.indexOf('http') !== -1) {
		if (isAppleDevice === false) {
			flash_f = document.getElementById('flash_player');
			if(flash_f){
				flash_f.playVideo(img_movie_rel);
			}
		}
		else {
			video.src = img_movie_rel;
			video.load();
			//alert(video.poster);
		}
	}
	else {
		if (isAppleDevice === false) {
			if(flash_f){
			flash_f.playVideo(baseHref + img_movie_rel);
			}
		}
		else {
			video.src = baseHref + img_movie_rel;
			video.load();
		}
	}
}
function initializeMap() {
    var latlng = new google.maps.LatLng(-34.397, 150.644);
    var myOptions = {
        zoom: 8,
        center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    map = new google.maps.Map(document.getElementById("map"),
        myOptions);
}
var moveArray = [];
//ipad touch thb film
function touchMoveFilmThb(e) {
	var targetEvent = e.touches.item(0);
    moveArray.push(e.targetTouches[0].pageY);
    if (moveArray.length >= 2) {
		if (moveArray[0] > moveArray[1]) {
			$('#movies_thb').css({ 'top': '-' + Math.ceil(((moveArray[0]-710)/384)*thbDelta)  + 'px' });
		} else {
			$('#movies_thb').css({ 'top': '+' + Math.ceil(((moveArray[1]-710)/384)*thbDelta)  + 'px' });
		}
		moveArray = [];
	}
    e.preventDefault();
    return false;
}
	/*$(window).load(function(){
		$('#product_popup_img').imagefit();
	});*/

$(document).ready(function () {
    var pageH = documentSize();
    if ($('#scribe_bgd').length > 0) {
        /*$('#scribe_bgd').maxImage({
        isBackground: true,
        maxFollows: 'width',
        verticalAlign: 'top',
        verticalOffset:(0),
        horizontalOffset:(0),
        position:('absolute'),
        topSpace:(-30),
        bottomSpace:(87),
        overflow: 'visible',
        horizontalAlign: 'left'
        });
        scribeSubTabsSwitch();*/
        $(window).load(function(){
            setTimeout(function () { scribeContainerUpd(); }, 300);
            if ($('.col_1').length > 0) {
                //setTimeout(function () { scribeColumnHeight(); }, 500);
                scribeColumnHeight();
            }
        });
        
        if ($('#scribe_bgd').hasClass('made-to-order') === true) {
            scribeSubTabsSwitch();

        }
        scribeBgdHeight();
        /* $(window).load(function () {
        setTimeout(function () { scribeContainerUpd(); }, 300);
        });*/
    }
    productSliderSetup();
    //setTimeout(function(){scribeContainerUpd();},500);
    $('.wishbag_container').css('display', 'block');
    activateFilmButtons();
    film_setup();
	if($('#scribeRight').length>0){
		film_setup_scribe();
	}

    if (lang !== null && (lang == 'en' || lang == 'fr' || lang == 'ge' || lang == 'it' || lang == 'es')) {
        Cufon.replace('#mainMenu li a, .subtitle p,#share_modal li a, #share_modal h3,#reply-title,.back, #locator_page h2,#text_page h2, #contact_page h2, #scribe_menu ul li a, .product_tabs_menu li a, #info_box ul li a, .group_header_second, #career_page h2,.career_circle a, .job .view, #changeLangContainer h1', { fontFamily: 'BallyLibris', hover: 'true' });
        Cufon.replace('.entry-title a, .film_desc h1,#film_content h2, .heritage_info_box h6, #h_timeline ul li , .group_header, #tab_id, #scribeContent h3', { fontFamily: 'Adobe Garamond Pro' });
        //Cufon.replace('.entry-title, .film_desc h1,#film_content h2,#h_timeline ul li  ', { fontFamily: 'Adobe Garamond Pro' });
        Cufon.now();
    }

    var lngLenght = $('#lngList li').length;
    $('.hasSub ul').show().css('visibility', 'hidden');
    $('.hasSub.active ul').css('visibility', 'visible');
    var bagLeft = $('#bagStatus').offset();
    //srodkowanie elementow podmenu
    var liF;
    var indexOfActive;
    if (home === true) {
        $('#mainMenu li.active').children('ul').css('visibility', 'hidden');
    }
	var mainActInd = $('#mainMenu li.active').index();
    if (mainActInd >0) {
        subMenuPos($('.hasSub.active'));
    }
    $('.hasSub').hover(function () {
        liF = $(this).index();
        dl = 0;
        indexOfActive = $('#mainMenu li.active').index();
        if (liF !== indexOfActive) {
            $(this).children('ul').css('visibility', 'visible');
            if (liF !== 0) {
                subMenuPos($(this));
            }
            $('.hasSub.active ul').css('visibility', 'hidden');
        }
        else {
            if (home === true) {
                $('#mainMenu li.active').children('ul').css('visibility', 'visible');
            }
        }
    }, function () {
        if (liF !== indexOfActive) {
            $(this).children('ul').css('visibility', 'hidden');
            if (home === false) {
                $('.hasSub.active ul').css('visibility', 'visible');
            }
        }
        else {
            if (home === true) {
                $('#mainMenu li.active').children('ul').css('visibility', 'hidden');
            }
        }
    });
    //share ipla 
    var blank_link_array;
    $('.shareLink').bind('click', function () {
        blank_link_array = new Array();

        $('#share_modal ul li a').each(function () {
            blank_link_array.push($(this).attr('href'));
        });

        if (lang !== null && (lang == 'en' || lang == 'fr' || lang == 'ge' || lang == 'it' || lang == 'es')) {
            Cufon.replace('#share_modal li a', { fontFamily: 'BallyLibris' });
            Cufon.replace('#share_modal h3', { fontFamily: 'BallyLibris' });
            //Cufon.now();
        }

        shareLink = $(this).attr('href');
        $('#share_modal ul li a').each(function () {
            var hrefT = $(this).attr('href');
            $(this).attr('href', hrefT.replace('shareLink', shareLink));
            hrefT = $(this).attr('href');
            $(this).attr('href', hrefT.replace('shareLink2', shareLink));
        });
        var pageSize = documentSize();
        var bgdW = '100%';
        if (isAppleDevice === true) {
            bgdW = '1020px';
        }
        $('body').append('<div id="bgd" style="width:' + bgdW + '; height:' + pageSize[1] + 'px;"></div>').fadeIn(100, function () {
            $('#share_modal').fadeIn(fade_time);
        });

        return false;
    });
    $('#modal_close').click(function () {
        $('#share_modal').fadeOut(fade_time, function () {
            $('#bgd').fadeOut(fade_time).remove();
            $('#share_modal ul li a').each(function (k) {
                $(this).attr('href', blank_link_array[k]);
            });
        });
        return false;
    });
    placeGalleryImages('sl_img_b');
    //placeGalleryImages('sl_img_s');
    //heritage info click
    //if(isAppleDevice===false)
    //{

    $(window).resize(function () {
        if (this.resizeTO) clearTimeout(this.resizeTO);
        this.resizeTO = setTimeout(function () {
            $(this).trigger('resizeEnd');
        }, 200);
    });
    //movies thb click
    $('#movies_thb a').click(function () {
        active_movie = $(this).index();
        changeMovie();
        return false;
    });
    $(window).bind('resizeEnd', function () {
        if ($('#product_popup').css('visibility') === 'hidden') {
            if ($('#bottom_list_lev2').length > 0) {
                productLev2Setup();
            }
            else {
                productSliderSetup();

            }
        }
        if ($('#scribeContainer').length > 0) {
            //scribeContainerUpd();
        }
        if ($('#scribe_bgd').length > 0) {
            scribeBgdHeight();
        }
    });
    sliderVsetup();
	$('#film_desc_container').css('width', $('.film_desc').length * filmW);
    $('.scribeAppHolder #film_desc_container').css('width', ($('.film_desc').length * 745));


    if ($('#locator_page').length > 0 || $('#store_details').length > 0) {
        storeLocatorSetup();

    }
    var sn = $('.film').eq(active_movie).attr('rel');

    if (sn) {
        if (sn.indexOf('http') !== -1) {
            sn = sn;
        }
        else {
            sn = baseHref + sn;
        }
    }
    var hostCheck = window.location.href;
    //ipad store locator
    $('#ipad_gps').click(function () {
        loadJsonLatLng();
        stores_count = 0;
        navigator.geolocation.getCurrentPosition(
		function (pos) {
		    var lat = pos.coords.latitude;
		    var lng = pos.coords.longitude;
		    initializeMap();
		    for (i = 0; i < stores_latlang.length; i++) {
		        nearestStore(lat, lng, stores_latlang[i][0], stores_latlang[i][1], stores_latlang[i][3]);
		    }
		},
		function () {
		});
    });
    $('#ipad_list').click(function () {
        $('#ipad_store_circles').fadeOut(fade_time, function () {
            $('#storeTable').fadeIn(fade_time);
        });
    });
    video = document.getElementsByTagName('video')[0];
    $('#play').toggle(function () {
        //video = document.getElementsByTagName('video')[0];
        setTimeout(video.play(), 400);
        $(this).addClass('stop');
        $('.ipadFilmPage #movies_container img').eq(active_movie).css('z-index', 0);
        filmDuration = video.duration;
        setTimeout(function () { _progressTimeout(); }, 500);
    }, function () {
        $(this).removeClass();
        video.pause();
        //$('.ipadFilmPage #movies_container img').eq(active_movie).css('z-index',2999);
    });
    $('#fullscreen').click(function () {
        video.webkitEnterFullscreen();
    });
    $('#bagStatus').bind("mouseenter", function () {
        wishBagSlide($(this));
    });
    $('.b2s').click(function () {
        var actCount = $('#storeTable ul li.act').length;
        if (actCount === 1) {
            cloudClean('country');
            $('#country').fadeOut(fade_time);
            $('#storeTable ul li.act').removeClass('act');
        }
        else {
            $('#storeTable ul li.act').eq($('#storeTable ul li.act').length - 2).click();
        }
        return false;
    });
    $('#v_down').click(function () {
        video.muted = true;
    });
    $('#v_up').click(function () {
        video.muted = false;
    });
    $("#film_timeline").slider({
        min: 0,
        max: 674,
        stop: function (event, ui) {
            video.currentTime = ui.value / 674 * video.duration;
        }
    });
    heritageCount = $('.sl_img_b').length - 1;
    var lhi = $('.sl_img_b').eq(heritageCount);

    var heritage_width = parseInt(lhi.css('width')) + parseInt(lhi.css('left'));

    $('#heritage_left').click(function () {
        if (heritageBlock === 0) {
            heritageBlock = 1;
            heritageNavigate('left', heritage_width);
        }
    });
    $('#heritage_right').click(function () {
        if (heritageBlock === 0) {
            heritageBlock = 1;
            heritageNavigate('right', heritage_width);
        }
    });

    thbDelta = Math.ceil($('#movies_thb a').length / 2) * 99 - 384;

    if (isAppleDevice === true) {
        //iscroll
        /*if(pid==='736'){
        var myScroll;
        var a = 0;
        function loaded() {
        myScroll = new iScroll('sl_big', {
        desktopCompatibility:true,
        onScrollEnd: function () {
        var ipadHeritagePos = $('#sl_big').css('-webkit-transform');
        var ipadMatrix = ipadHeritagePos.split(',');
        var ipadHeritageIndex;
        $('.sl_img_b').each(function(){
        if($(this).attr('title')<Math.abs(ipadMatrix[4])){
        ipadHeritageIndex = $(this).attr('rel');
        }
        });
        //$('#timeborder').animate({'left':(timeSlide[ipadHeritageIndex-1])+'px'});
        }	
        });
        }
        loaded();
        }*/
        if ($('#movies_thb').length > 0) {
            var myScroll2;
            var a = 0;
            function loaded2() {
                $('#movies_thb').css('height', Math.ceil($('#movies_thb a').length / 2) * 99);
                myScroll2 = new iScroll('movies_thb', {
                    desktopCompatibility: true
                });
            }
            loaded2();
        }
    }
    var newsletter_text = $('#newsletter_input').val();
    $('#newsletter_input').focus(function () {
        if ($(this).val() === newsletter_text) {
            $(this).val('');
        }
    });
    $('#newsletter_input').blur(function () {
        if ($(this).val() === '') {
            $(this).removeClass();
            $(this).val(newsletter_text);
        }
    });
    $('#newsletter_send').click(function () {
        checkNewsletter();
    });
    /*$(window).resize(function () {	
    if (this.resizeTO) clearTimeout(this.resizeTO);
    this.resizeTO = setTimeout(function () {
    $(this).trigger('resizeEnd');
    }, 10);
    });
    $(window).bind('resizeEnd', function () {
    scribeContainerUpd();
    });
    */
    $('#prevSubTab').click(function () {
        subTabNavigate('left');
        return false;
    });
    $('#nextSubTab').click(function () {
        subTabNavigate('right');
        return false;
    });

    $('#scribe_flash_play').click(function () {
        var imgSrc = $(this).children('img').attr('rel');
        $.fancybox({
            'padding': 0,
            'autoScale': false,
            'transitionIn': 'none',
            'transitionOut': 'none',
            'title': this.title,
            'width': 970,
            'height': 555,
            'href': baseHref + 'site/swf/vp_small.swf',
            'type': 'swf',
            'swf': {
                'wmode': 'transparent',
                'allowfullscreen': 'true',
                ' flashvars': 'streamName=' + this.rel + '&streamPreview=' + imgSrc + ''
            }
        });

        return false;
    });
    $('#scribe_html_play').click(function () {
        var imgSrc = $(this).children('img').attr('rel');
        $.fancybox('<video width="858" height="482"  controls poster="' + imgSrc + '" src="' + $(this).attr("rel") + '"></video>');
        return false;
    });
    $('#bottom_list ul li').click(function () {
        if ($(this).hasClass('product_look_image') === false) {
            var thb_indx = $(this).index();

            $('#bottom_list ul li.act').removeClass('act');
            $(this).addClass('act');
            onOffPrevNext(thb_indx);
            if ($('.product_look_image').length > 0) {
                thb_indx--;
            }
            $('#top_list ul').animate({ 'left': -810 * thb_indx + 'px' }, fade_time);
        }
        return false;
    });
    if ($('.product_look_image').length > 0) {
        $('#bottom_list ul li').eq(1).addClass('act');
    }
    else {
        $('#bottom_list ul li').eq(0).addClass('act');
        $('#bottom_list_lev2 ul li').eq(0).addClass('act');
    }
    $('#prod_controls ul.thbs li').click(function () {
        prod_navigate($(this));
    });
    $('#enlarge').click(function () {
        var mainH = $('#main').height();
        $('#product_popup').css('height', mainH);
        //$('#product_popup_img').css({'height':mainH,'width':mainH*1.49425});
        var prod_popup_imgH = $('#product_popup_img').height();
        var overflowH = prod_popup_imgH - mainH;
        //console.log(prod_popup_imgH);
        //$('#product_popup_img').css('margin-top',overflowH);
        $('#product_popup').mousemove(function (e) {
            var x = e.pageX - this.offsetLeft;
            var y = e.pageY - 87;
            //if(y<overflowH){
            //	$('#product_popup_img').css('margin-top', overflowH - y );
            //}
            //if(y>mainH-overflowH){
            //console.log(y-mainH);
            //$('#product_popup_img').css('margin-top', -(overflowH) - (y-mainH) );
            //$('#product_popup_img').css('margin-top', -(overflowH-mainH+y) );
            //}
            var ratioY = y / mainH;
            $('#product_popup_img').css('margin-top', -(overflowH * ratioY));
        });
        var large_img = $('.thbs .act img').attr('rel');
        var actIndex = $('.thbs .act').index();
        var pageWH = documentSize();
        $('#product_popup_img').attr('src', large_img);
        $('#prod_thumb_list_popup ul li.act').removeClass('act');
        $('#prod_thumb_list_popup ul li').eq(actIndex).addClass('act');
        $('#product_popup').width('css', pageWH[0]);
        $('#product_popup').css('visibility', 'visible');
        return false;
    });

    $('#pop_close').click(function () {
        $('#product_popup').css('visibility', 'hidden');
        return false;
    });
    $('#prod_thumb_list_popup ul li').click(function () {
        var thb_indx = $(this).index();
        $('#prod_thumb_list_popup ul li.act').removeClass('act');
        $('#product_popup_img').attr('src', $(this).children('img').attr('rel'));
        $(this).addClass('act');
        return false;
    });
    $('#info_box ul li a').click(function () {
        if ($(this).hasClass('act') === false) {
            var div2displ = $(this).attr('href');
            $('#info_box .act').removeClass('act');
            //$('#info_box ul li a').removeClass('act');
            $('#' + div2displ).addClass('act');
            $(this).addClass('act');
            $(this).parent('li').addClass('act');
            descDetSlider();
        }
        return false;
    });
    productLev2Setup();
    descDetSlider();
    $('#next_prod').click(function () {
        var actIndx = $('#bottom_list ul li.act').index();
        actIndx++;
        prod_anim('next', actIndx);
        return false;
    });
    $('#prev_prod').click(function () {
        var actIndx = $('#bottom_list ul li.act').index();
        actIndx--;

        prod_anim('prev', actIndx);
        return false;
    });
    descLiHeight();
    //flashMoviePlay();
    /*if($('.product_tabs_menu').length>0){
    viewAllLinks();
    }*/
    //$('.product_tabs_menu ul').eq(0).children('li').css('position','relative');
    if ($('#career_page').length > 0) {
        careerCircles();
        inputFocus('job_apply');
    }
    /*$('#homePageModules').click(function (e) {
        if (e.target.id === 'homePageModules') {
            window.location.href = baseHref + 'world-of-bally/heritage/1851-1920s/';
        }
    });*/
    if ($('#change_language').length > 0) {
        $('#change_language li').click(function () {
            $('#lang_param').val($(this).attr('id'));
            $('#lng_form').submit();
        });
    }
});                                   
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////document.ready end

/*function viewAllLinks(){
		$('.product_tabs_menu ul').eq(0).children('li').each(function(key,value){
				var allLink =$(this).children('a').attr('href');
				lastLiHtml = '<li class="all"><a href="'+allLink+'">view all</a></li>';
				$(this).children('li ul').append(lastLiHtml);
				Cufon.now();
		});
}*/
/*
	$('#' + k).filter(function(){
			if (this.value.match(val) === null) {
				$('#' + k).addClass('Error');
				hasError.push(k);
			} else {
				$('#' + k).removeClass();
				$('#newsletter_form').submit();
			}
		});

*/
function scribeBgdHeight() {
    var pageWH = documentSize();
    sBgdH = pageWH[2] - 174;
    if (sBgdH > $('#scribeContainer').height()) {
        $('#scribe_bgd').css('height', sBgdH + 'px');
   }
}
function inputValidate(input_id,pattern){
	var patterns = {'val_txt': /^[a-zA-Z_\s-]{2,}$/,'val_nr' : /^[0-9]{2,}$/,'val_email' : /^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+$/}
		if ($('#' + input_id).val().match(patterns[pattern]) === null) {
			$('#' + input_id).addClass('error');
		} else {
			$('#' + input_id).removeClass('error');
		}	
}
function inputFocus(formClass){
	$('.'+formClass+' input:text').each(function(){
		var input_txt = $(this).attr('rel');
		$(this).val(input_txt);
		$(this).focus(function(){
			if($(this).val()===input_txt){
				$(this).val('');
			}
		});
		$(this).blur(function(){
			if($(this).val()===''){
			$(this).val(input_txt);
			
		}
		inputValidate($(this).attr('id'),$(this).attr('title'));
		});
	});
}
function careerCircles(){
	$('.career_circle a').each(function(){
		var link_h = $(this).height();
		var link_padding = (125-link_h)/2;
		$(this).css({'padding-top':link_padding,'padding-bottom':link_padding,'height':link_h});
		
	});
}
function descLiHeight(){
	var liDesc = $('#info_box ul li a');
	var li1h = liDesc.eq(0).height();
	var li2h = liDesc.eq(1).height();
	if(li1h>li2h){
		liDesc.eq(1).css('height',li1h);
	}
	else{
		liDesc.eq(0).css('height',li2h);
	}
}
function prod_anim(dir, newIndx){
	$('#bottom_list ul li').eq(newIndx).click();
	onOffPrevNext(newIndx);
}

function onOffPrevNext(actIndx){
	if($('.product_look_image').length>0){
		if(actIndx>1){
			$('.prev').css('visibility','visible');
		}
		if(actIndx===1){
			$('.prev').css('visibility','hidden');
		}
		if(actIndx===$('#bottom_list ul li').length-1){
			$('.next').css('visibility','hidden');
		}
		else{
			$('.next').css('visibility','visible');
		}
	}
	else{
		if(actIndx>0){
			$('.prev').css('visibility','visible');
		}
		if(actIndx===0){
			$('.prev').css('visibility','hidden');
		}
		if(actIndx===$('#bottom_list ul li').length-1){
			$('.next').css('visibility','hidden');
		}
		else{
			$('.next').css('visibility','visible');
		}
	}
}
function prod_navigate(_this){
	var thb_indx = _this.index();
	$('#prod_controls ul.thbs li.act').removeClass('act');
	_this.addClass('act');
	$('#top_list_level2 ul').animate({'left':-1020*thb_indx+'px'},fade_time);
}
function descDetSlider(){
	var slideOffset = $('#info_box div.act p').height()-112;
	if(slideOffset>0){
		$('#info_box  #slider_vbgd').show();
		$('#info_box #slider_v').slider({
			orientation: "vertical",
			min: 0,
			max: slideOffset,
			value: slideOffset,
			slide: function (event, ui) {
				 $('#info_box div.act p').css({ 'top': ui.value -slideOffset });
			}
			
		});
	}
	else{
		$('#info_box  #slider_vbgd').hide();
	}
	$('#info_box div.act p').css('top',0);
}
function productLev2Setup(){
	var top_list_width = $('#top_list_level2 ul li').length * 1020;
	$('#top_list_level2 ul').css('width',top_list_width);
	var pageWH = documentSize();
	var sliderW = pageWH[0] - 26;
	var bottom_list_width = $('#bottom_list_lev2 ul li').length * 156;
	$('#bottom_list_lev2 ul').css('width',bottom_list_width);
	$("#single_prod #slider_bgd").css('width', sliderW);
	$("#single_prod #product_slider").css('width', sliderW-35);
	$("#single_prod #product_slider").slider({
			min: 0,
			max: bottom_list_width-pageWH[0],
			slide: function (event, ui) {
				$('#bottom_list_lev2 ul').css({ 'left': -ui.value });
			}
	});
	 if (pageWH[0] > bottom_list_width) {
        $("#single_prod #slider_bgd").css('display', 'none');
        $('#top_list_level2').animate({ 'left': 0 }, fade_time);
       $('#bottom_list_lev2 ul').animate({ 'left': 0 }, fade_time);
    }
    else {
        $("#single_prod #slider_bgd").css('display', 'block');
    }
    if (pageWH[0] > bottom_list_width) {
       $('#bottom_list_lev2 ul').animate({ 'left': 0 }, fade_time);
    }
}
function subTabNavigate(direction){
	scribeSubTabsLength = $('.sub_tab').length-1;
	if(direction==='right'){
		if(activeScribeSubTab<scribeSubTabsLength){
			$('#prevSubTab').removeClass('disable');
			activeScribeSubTab++;
			if(activeScribeSubTab===scribeSubTabsLength){
				$('#nextSubTab').addClass('disable');
			}
			$('.visible_tab').fadeOut(fade_time,function(){
				$(this).attr('class','hidden_tab sub_tab');
				
				$('.sub_tab').eq(activeScribeSubTab).fadeIn(fade_time,function(){
					$(this).attr('class','visible_tab sub_tab');
				});
			});
			$('#tab_id').text(activeScribeSubTab+1+'.');
		}
	}
	else{
		if(activeScribeSubTab>0){
			if(activeScribeSubTab===scribeSubTabsLength){
				$('#nextSubTab').removeClass('disable');
			}
			activeScribeSubTab--;
			if(activeScribeSubTab===0){
				$('#prevSubTab').addClass('disable');
			}
			$('.visible_tab').fadeOut(fade_time,function(){
				$(this).attr('class','hidden_tab sub_tab');
				$('.sub_tab').eq(activeScribeSubTab).fadeIn(fade_time,function(){
					$(this).attr('class','visible_tab sub_tab');
				});
			});
		}
		$('#tab_id').text(activeScribeSubTab+1+'.');
	}
	Cufon.replace('#tab_id', { fontFamily: 'Adobe Garamond Pro' });Cufon.now();
	setTimeout(function(){scribeSubTabsSwitch();},600);
	
	//$(window).load(function(){
		//setTimeout(function(){scribeContainerUpd();},300);
	//});	
}
function scribeContainerUpd(){
	var scribeH = $('#scribeContent').height();
	var bgdH = $('#scribe_bgd').height();
	if(scribeH<bgdH){
		$('#main').css('height',$('#scribeContainer').css('height',$('#scribe_bgd').height()));
		//setTimeout(function(){$('#scribeContainer').css('height',$('#scribe_bgd').height()-79);},100);
		setTimeout(function(){
			if($('#scribeContainer').css('height')<$('#scribe_bgd').height()){
				
				$('#scribeContainer').css('height',$('#scribe_bgd').height());
		}
			else{
				$('#scribe_bgd').css('height',$('#scribeContainer').height());
			}
		},300);
	}
	else{
		setTimeout(function(){$('#scribe_bgd').css('height',$('#scribeContent').height());},100);
		/*setTimeout(function(){$('#scribeContainer').css('height',$('#scribe_bgd').height()+30);},200);*/
		setTimeout(function(){
			if($('#scribeContainer').css('height')<$('#scribe_bgd').height()){
				
				$('#scribeContainer').css('height',$('#scribe_bgd').height());
		}
			else{
				$('#scribe_bgd').css('height',$('#scribeContainer').height()+30);
			}
		},300);
	}
	
	//$('html').css({'height':$('#wrap').height(),'overflow-y':'scroll'});
	//$('html').css({'overflow-y':'scroll'});
}
function scribeSubTabsSwitch(){
    //$('#scribe_bgd').attr('rel',$('.sub_tab').eq(activeScribeSubTab).attr('rel'));
    //$('#scribe_bgd').addClass('sub' + activeScribeSubTab);
    $('#scribe_bgd').css('background', 'url(' + $('.sub_tab').eq(activeScribeSubTab).attr('rel') + ') 0 0 repeat');
    $('#scribe_bgd').css({ 'display': 'block !important' });
        var sColumn = $('.visible_tab .scribeColumn');
        if ($('.col_1').length > 0) {
            setTimeout(function () { scribeColumnHeight(); }, 200);
        }
}
function scribeColumnHeight() {
    var sColumn;
    if ($('.visible_tab').length>0) {
        sColumn = $('.visible_tab #scribeTxt .scribeColumn');
       
    }
    else {
        sColumn = $('.scribeColumn');
    }
    var col1 = sColumn.eq(0).height();
    var col2 = sColumn.eq(1).height();
    if (col1 > col2) {
        var col2 = col1;
    }
    sColumn.css('height', col2);
}
function checkNewsletter(){
	$.each(newsArray, function(k, val){
		$('#' + k).filter(function(){
			if (this.value.match(val) === null) {
				$('#' + k).addClass('Error');
				hasError.push(k);
			} else {
				$('#' + k).removeClass();
				$('#newsletter_form').submit();
			}
		});
	});
}
function heritageNavigate(direction, heritage_width){
	var pageWH = documentSize();
	var slideValue = $('.sl_img_b').eq(heritageActive).css('width');
	//	var timeGroup;
	slideValue = parseInt(slideValue) + 16;
	var newPos = parseInt(parseInt($('#heritage_slider').css('left')) - slideValue) + 'px';
	if (direction === 'right') {
		if (heritageActive === 0) {
			if (isAppleDevice === false) {
				$('#sl_big_cont').animate({
					'margin-left': 0
				}, fade_time, function(){
				
				});
				
			}
			$('#heritage_left').fadeIn(fade_time);
		}
		
		if (isAppleDevice === false) {
		
			$('#heritage_slider').animate({
				'left': newPos
			}, fade_time, function(){
				//	if (heritage_width + parseInt($('#heritage_slider').css('left')) < pageWH[0]) {
				if ((-1) * heritageActive >= (heritage.length - 4)) {
					$('#heritage_right').fadeOut(fade_time);
				}
				addNewItems((-1) * heritageActive);
			});
		}
		else
		{
			$('#heritage_left').fadeIn(fade_time);
			//var t = $('.sl_img_b').eq(heritageActive).css('left');
			if (heritageActive === 0) {
				heritageXipad = slideValue*(-1)+'px';
			}
			else{
				heritageXipad= heritageActive*parseInt(newPos) -slideValue*(-1);
				heritageXipad =heritageXipad*(-1)+'px';
				
			}
			//$('#heritage_slider').css({'-webkit-transition': 'all 0.5s linear','-webkit-transform': 'translate('+heritageXipad+')'});
			$('#heritage_slider').css({'-webkit-transition-property': 'all','-webkit-transition-duration': '0.5s','-webkit-transform': 'translate('+heritageXipad+')'});
			if ((-1) * heritageActive >= (heritage.length - 4)) {
					$('#heritage_right').fadeOut(fade_time);
				}
			addNewItems((-1) * heritageActive);		
		}
		heritageActive--;
	}
	else {
		if (heritageActive === 1) {
			if (isAppleDevice === false) {
				$('#sl_big_cont').animate({
					'margin-left': '85px'
				}, fade_time, function(){
				});
				
			}
			$('#heritage_left').fadeOut(fade_time);
		}
		
		if (isAppleDevice === false) {
			$('#heritage_slider').animate({
				'left': '+=' + slideValue + ''
			}, fade_time, function(){
			//	if (heritage_width + parseInt($('#heritage_slider').css('left')) > pageWH[0]) {
				if ((-1) * heritageActive < (heritage.length - 3)) {
					$('#heritage_right').fadeIn(fade_time);
					
				}
			});
		}
		else{
			heritageXipad= parseInt(heritageXipad) + 342;
			heritageXipad =heritageXipad+'px';
			//$('#heritage_slider').css({'-webkit-transition': 'all 0.5s linear','-webkit-transform': 'translate('+heritageXipad+')'});
			//$('#heritage_slider').css({'-webkit-transition-property': 'left','-webkit-transition-timing-function': 'cubic-bezier(1,0,1,0)','-webkit-transform': 'translate('+heritageXipad+')'});
			$('#heritage_slider').css({'-webkit-transition-property': 'all','-webkit-transition-duration': '0.5s','-webkit-transform': 'translate('+heritageXipad+')'});
			
		}
		heritageActive++;
		if(heritageActive === 0){
			$('#heritage_left').fadeOut(fade_time);
		}
		
		//	timeGroup = $('.sl_img_b').eq(heritageActive).attr('rel');
	}
	setTimeout(function(){heritageBlock = 0;},500);
	//console.log(heritageActive);
	//$('#timeborder').animate({'left':(timeSlide[timeGroup-1])+'px'});
}
/*var setRemoveCallback = function () {
    __flash__removeCallback = function (instance, name) {
        if (instance) {
            instance[name] = null;
        }
    };
    window.setTimeout(setRemoveCallback, 10);
}
setRemoveCallback();*/

