function updateScrollPanes() {
	$('.scroller').jScrollPane(
			// jScrollPane parameters
			{
				verticalDragMinHeight: 16,
				verticalDragMaxHeight: 16,
				horizontalDragMinWidth: 16,
				horizontalDragMaxWidth: 16
			}
		);
}

function morePressed (idToHide, idToShow) {
	$(idToHide).hide();
	$(idToShow).show();
	updateScrollPanes();
}

function scrollToContent() {
	$('body').ready().stop().animate({
        scrollTop: 580 // Stop ___ pixels from the top
    }, 1500); //Animation style - easing plugin parameters
    
}

function scrollToVisor() {
	$('body').ready().stop().animate({
        scrollTop: 0 // Stop ___ pixels from the top
    }, 1500); //Animation style - easing plugin parameters
    
}

//assumes the url is something like http://www.youtube.com/watch?v=_g4vZnGwAac&feature=feedrec_grec_index
function get_youtube_embed_code(url) {
	i1 = parseInt(url.indexOf('v=')+2);
	i2 = parseInt(url.indexOf('&'));
	if(i2>-1)
		str = url.slice(i1,i2);
	else
		str = url.slice(i1);
	//alert(str);
	embed_code = '<iframe width="720" height="400" src="http://www.youtube.com/embed/'+str+'" frameborder="0" allowfullscreen></iframe>';
	return embed_code;
}

function get_vimeo_embed_code(url) {
	splits = url.split('?'); // First of all clean the url from the query string (erase anything after '?')
	url=splits[0];
	vimeocode = str_replace('http://vimeo.com/', '', url);
	embed_code = '<iframe src="http://player.vimeo.com/video/'+vimeocode+'?title=0&amp;byline=0&amp;portrait=0&amp;color=ffffff" width="640" height="360" frameborder="0"></iframe>';
	return embed_code;
}

function get_issuu_embed_code(url) {
	splits = url.split('?'); // First of all clean the url from the query string (erase anything after '?')
	url=splits[0];
	//alert(url);
	embed_code = '<iframe src="'+url+'?mode=embed&layout=http%3A%2F%2Fskin.issuu.com%2Fv%2Flight%2Flayout.xml&showFlipBtn=true" width="640" height="360"></iframe>';
	//embed_code = '<iframe src="'+url+'" width="720" height="400"></iframe>';
	return embed_code;
}

// IMMAGICGROUP ONLY
function get_issuu_embed_code_from_docname(docname) {
	//splits = url.split('?'); // First of all clean the url from the query string (erase anything after '?')
	//url=splits[0];
	//alert(url);
	embed_code = '<iframe src="http://issuu.com/immagic/docs/'+docname+'?mode=embed&layout=http%3A%2F%2Fskin.issuu.com%2Fv%2Flight%2Flayout.xml&showFlipBtn=true" width="640" height="360"></iframe>';
	return embed_code;
}


function set_visor_content(html) {
	$('#visor_content').html('<div class="visor_content_background"><div class="visor_media_object">'+html+'</div></div>');
}

function load_youtube_url_into_visor(url) {
	set_visor_content(get_youtube_embed_code(url));
}
function load_vimeo_url_into_visor(url) {
	set_visor_content(get_vimeo_embed_code(url));
}
function load_issuu_url_into_visor(url) {
	set_visor_content(get_issuu_embed_code(url));
}


function str_replace (search, replace, subject, count) {
    // %          note 1: The count parameter must be passed as a string in order
    // %          note 1:  to find a global variable in which the result will be given
    // *     example 1: str_replace(' ', '.', 'Kevin van Zonneveld');
    // *     returns 1: 'Kevin.van.Zonneveld'
    // *     example 2: str_replace(['{name}', 'l'], ['hello', 'm'], '{name}, lars');
    // *     returns 2: 'hemmo, mars'
    var i = 0,
        j = 0,
        temp = '',
        repl = '',
        sl = 0,
        fl = 0,
        f = [].concat(search),
        r = [].concat(replace),
        s = subject,
        ra = r instanceof Array,
        sa = s instanceof Array;
    s = [].concat(s);
    if (count) {
        this.window[count] = 0;
    }

    for (i = 0, sl = s.length; i < sl; i++) {
        if (s[i] === '') {
            continue;
        }
        for (j = 0, fl = f.length; j < fl; j++) {
            temp = s[i] + '';
            repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
            s[i] = (temp).split(f[j]).join(repl);
            if (count && s[i] !== temp) {
                this.window[count] += (temp.length - s[i].length) / f[j].length;
            }
        }
    }
    return sa ? s : s[0];
}
