﻿// JScript File
var images = [];
var infos = [];
var mouseX, mouseY;
var srcPortfolio = 'portfolio';
var ssCID = '';

ns4 = (document.layers) ? true : false;
ie4 = (document.all) ? true : false;

// ======================= Video Constants ===================
var defaultBottom = 0;
var defaultWidth = 350;
var defaultHeight = 350;
// ====================== End Video Constants ================

function swap_image(obj, newimage) {
    obj.src = newimage;
}

function preload_images() {
}

function showInfo(obj, modelId) {
    var infobox = document.getElementById("infobox");
    if (infobox != null) {
        infobox.innerHTML = infos[modelId];
        infobox.style.display = 'block';
		infobox.style.visibility = 'visible';
		infobox.style.top = (getAscendingTops(obj) + 10) + 'px';
		if (getAscendingTops(obj) + 10 < 0) infobox.style.top = '0px';
		infobox.style.left = (getAscendingLefts(obj) + obj.offsetWidth + 10) + 'px';
    }
}

function hideInfo()
{
	var infobox = document.getElementById("infobox");
	if (infobox != null)
	{
		infobox.style.display = 'none';
		infobox.style.visibility = 'hidden';
		infobox.style.top = '-999px';
		infobox.style.left = '-999px';
		infobox.style.zIndex = '500';
	}
}

function showCasting() {
    var casting = document.getElementById("casting");
    if (casting != null) {
        casting.style.display = 'block';
        casting.style.left = '156px';
        casting.style.top = '223px';
    }
    return false;
}

function hideCasting() {
    var casting = document.getElementById("casting");
    if (casting != null) {
        casting.style.display = 'none';
        casting.style.left = '-1000px';
        casting.style.top = '-1000px';
    }
}

function AddCart(url) {
	var fr = document.createElement("iframe");
	fr.id = "cart_id";
	fr.src = url;
	fr.style.display = 'none';
	document.body.appendChild(fr);
	window.fr = fr;
}

function getAscendingLefts(elem){
	if (!elem)
		return 0;
	else
		return elem.offsetLeft+getAscendingLefts(elem.offsetParent);
}

function getAscendingTops(elem){
	if (!elem)
		return 0;
	else
		return elem.offsetTop+getAscendingTops(elem.offsetParent);
}

function init() {
	if (ns4) { document.captureEvents(Event.MOUSEMOVE); }
	document.onmousemove = mousemove;
}

function mousemove(e) {
	if (ns4) { mouseX=e.pageX; mouseY=e.pageY; }
	if (ie4) { mouseX=event.x; mouseY=event.y; }
}

function ShowLarge(imageId) {
    var img = document.getElementById('largephoto');
    img.src = '/img/loading.gif';
    img.src = '/image.aspx?id='+imageId+'&s=model_photos&crop=true&width=' + img.width + '&height=' + img.height;
    document.getElementById('original').href = "javascript: Photo('model_photos', " + imageId + ")";
}

function Photo(src, imageId) {
    centerWindow('/showphoto.aspx?s=' + src + '&id=' + imageId);
}

function centerWindow(url) {
    var xMax, yMax;

    if (document.all) {
        xMax = screen.width;
        yMax = screen.height;
    } else
        if (document.layers) {
            xMax = window.outerWidth;
            yMax = window.outerHeight;
        }
        else {
        xMax = 640; yMax = 480;
    }

    var xOffset = (xMax - 600)/2, yOffset = (yMax - 600)/2;

    window.open(url,'Photo','width=600,height=600,screenX='+xOffset+',screenY='+yOffset+',top='+yOffset+',left='+xOffset+',copyhistory=no,directories=no, menubar=no,location=no,scrollbars=no,resizable=no') ;
}

function StartVideoPlayBack() {
    var url = window.location.href;
    var mainPageUrl = 'http://allymodels.ru/';
    var mainPageUrl_A1 = 'http://www.allymodels.ru/';
    var mainPageUrl_A2 = 'www.allymodels.ru';

    
    //Check For Main Page
    if (url === mainPageUrl || url === mainPageUrl_A1 || url === mainPageUrl_A2) {
        ShowMainVideo();
    } else {
        //Check for Girl [ http://allymodels.ru/models/6035.aspx?returnUrl=%2fgirls.aspx ]
        if (new RegExp('models[/]\\d+[.]aspx').test(url)) {
            var regexp = new RegExp('\\d+');
            var modelNum = regexp.exec(url);
            if (modelNum) {
                ShowVideoForModel(modelNum);
            }
        } 
    }
}

function ShowMainVideo() {
    ShowVideo('http://ispeakvideo.s3.amazonaws.com/Ally%20fashion/ally-fashion%2802928%29.swf ', '320px', null, -4, defaultWidth, defaultHeight);
}

function ShowVideoForModel(modelNum) {
    
    var matrixOfVideos =
    [
        ['http://ispeakvideo.s3.amazonaws.com/Ally%20fashion/ally-fashion%2802928%29.swf', 38],
        ['http://ispeakvideo.s3.amazonaws.com/Ally%20fashion/barskaya-cast.swf', 6372, 400],
        ['http://ispeakvideo.s3.amazonaws.com/Ally%20fashion/cast-bachinskaya%2802725%29.swf', 6342, 400],
        ['http://ispeakvideo.s3.amazonaws.com/Ally%20fashion/cast-bakulina%2802764%29.swf', 6374],
        ['http://ispeakvideo.s3.amazonaws.com/Ally%20fashion/cast-chayka-n.swf', 5179, 400],
        ['http://ispeakvideo.s3.amazonaws.com/Ally%20fashion/cast-bragina%2802850%29.swf', 6238],
        ['http://ispeakvideo.s3.amazonaws.com/Ally%20fashion/cast-guzeeva%2802545%29.swf', 5879, 400],
        ['http://ispeakvideo.s3.amazonaws.com/Ally%20fashion/cast-korelova%2802471%29.swf', 5740, 450],
        ['http://ispeakvideo.s3.amazonaws.com/Ally%20fashion/cast-libina%2802520%29.swf', 6375, 400],
        ['http://ispeakvideo.s3.amazonaws.com/Ally%20fashion/cast-meer%2802811%29.swf', 6373, 340],
        ['http://ispeakvideo.s3.amazonaws.com/Ally%20fashion/cast-posdnyakova.swf', 6193],
        ['http://ispeakvideo.s3.amazonaws.com/Ally%20fashion/cast-sablina%2802530%29.swf', 2188, 400],
        ['http://ispeakvideo.s3.amazonaws.com/Ally%20fashion/cast-sergeeva-d%2802575%29.swf', 6343, 400],
        ['http://ispeakvideo.s3.amazonaws.com/Ally%20fashion/cast-tolkacheva%2802526%29.swf', 6211, 400],
        ['http://ispeakvideo.s3.amazonaws.com/Ally%20fashion/cast-turina%2803067%29.swf', 6376],
        ['http://ispeakvideo.s3.amazonaws.com/Ally%20fashion/cast-yakovleva%2802563%29.swf', 6344, 400],
        ['http://ispeakvideo.s3.amazonaws.com/cast/cast-oks.swf', 3677],
        ['http://ispeakvideo.s3.amazonaws.com/Ally%20fashion/cast-ekaterina%2802510%29.swf', 735, 400],
        ['http://ispeakvideo.s3.amazonaws.com/Ally%20fashion/cast-kachetkova%2802584%29.swf', 6194],
        ['http://ispeakvideo.s3.amazonaws.com/Ally%20fashion/cast-zolotaya%2802592%29.swf', 6190],
        ['http://ispeakvideo.s3.amazonaws.com/Ally%20fashion/cast-gardeiko%2802740%29.swf', 2712, 340],
        ['http://ispeakvideo.s3.amazonaws.com/Ally%20fashion/cast-variva%2802610%29.swf', 6189],
        ['http://ispeakvideo.s3.amazonaws.com/Ally%20fashion/cast-dulo.swf', 4430],
        ['http://ispeakvideo.s3.amazonaws.com/Ally%20fashion/cast-silaeva%2803448%29.swf', 6502],
        ['http://ispeakvideo.s3.amazonaws.com/Ally%20fashion/cast-danilova%2802501%29.swf', 6519],
        ['http://ispeakvideo.s3.amazonaws.com/Ally%20fashion/cast-kashirina%2802578%29.swf', 6515],
        ['http://ispeakvideo.s3.amazonaws.com/Ally%20fashion/cast-grivneva%2802612%29.swf', 6514],
        ['http://ispeakvideo.s3.amazonaws.com/Ally%20fashion/cast-kopitina%2802779%29.swf', 6518]
    ];

    for (var i = 0; i < matrixOfVideos.length; i++) {
        if (parseInt(matrixOfVideos[i][1]) === parseInt(modelNum)) {

            var customLeft = 150;
            
            if (!matrixOfVideos[i][2]) {
                
                if (    modelNum == 6193 || modelNum == 6376 || modelNum == 3677 ||
                        modelNum == 6194 || modelNum == 6190 || modelNum == 6189 ||
                        modelNum == 4430 || modelNum == 6502 || modelNum == 6519 ||
                        modelNum == 6515 || modelNum == 6514 || modelNum == 6518 || 
                        modelNum == 6238) {
                    customLeft = customLeft + 30;
                }

                ShowVideo(matrixOfVideos[i][0], customLeft.toString() + 'px', null, defaultBottom, defaultWidth, defaultHeight);
            }
            else {

                var customBottom = defaultBottom - 23;
                customLeft = 184;

                if (matrixOfVideos[i][2] === 450) {
                    customLeft = customLeft - 44;
                    customBottom = customBottom - 26;
                }

                if (matrixOfVideos[i][2] === 340) {
                    customBottom = customBottom + 15;
                }

                ShowVideo(matrixOfVideos[i][0], customLeft.toString() + 'px', null, customBottom, matrixOfVideos[i][2], matrixOfVideos[i][2]);
            }
            break;
        }
    }
}

function ShowVideo(videoUrl, left, top, bottom, width, height) {
    var divObj = document.getElementById('videoWrapper');
    if(divObj) {

        divObj.style.position = 'fixed';
        divObj.style.width = width.toString() + 'px';
        divObj.style.height = height.toString() + 'px';
        divObj.style.left = left;
        divObj.style.zIndex = 101;
        divObj.style.textAlign = 'center';
        divObj.style.verticalAlign = 'bottom';
        
        if (top) {
            divObj.style.top = top;
        }

        if (bottom !== null) {
            divObj.style.bottom = bottom.toString() + 'px';
        }

        FlashInserter.insert('videoFile', videoUrl, width, height, function () { });
    }
}

function afterFlashHide() {
     var divObj = document.getElementById('videoWrapper');
     if (divObj) {
         divObj.style.display = 'none';
     }
}

FlashInserter = (function () {
    return {
        /**
        * Вставляет флэшку по указанному ID элемента
        * @param {String} nodeID ID элемента
        * @param {String} movie URL swf-файла
        * @param {Number} width Ширина ролика
        * @param {Number} height Высота ролика
        * @param {Function} callback Коллбэк по вставке, может быть пропущен или null
        **/
        insert: function (nodeId, movie, width, height, callback) {
            $('#' + nodeId).empty().show();
            var params = {
                wmode: 'transparent',
                AllowScriptAccess: 'always',
                name: nodeId,
                swliveconnect: true
            };
            var actualCallback = (callback) ? callback : function () { };
            setTimeout(function () {
                swfobject.embedSWF(movie, nodeId, width, height, '9.0.0.0', {}, params, params, {}, actualCallback);
                $('#' + nodeId).addClass('inserted-flash');
            }, 100);
        },
        /**
        * Прячет флэшку по указанному ID её контейнера
        * @param {String} nodeID ID контейнера
        * */
        hide: function (nodeId) {
            // Клин клином вышибают
            if ($.browser.msie) {
                 swfobject.embedSWF('?stub=fix_msie', nodeId, 1, 1, '9.0.0.0', { }, { }, { });
            }
            $('#' + nodeId).hide().removeClass('inserted-flash').empty();
        },
        //Гасит и прячет все вставленные флэшки на странице
        hideAll: function () {
            hideWhenFinished();
        }
    };
})();
// Флэшка требует
if (typeof hideWhenFinished == 'undefined') {
    hideWhenFinished = function() {
        $('.inserted-flash').each(function() {
            FlashInserter.hide($(this).attr('id'));
        });
        if (typeof afterFlashHide != 'undefined')
            afterFlashHide();
    };
}
