var search_value = '';

function toggle_box(search_box) {
	if (!search_box) search_box = document.getElementById("search_box");
	
	// if (search_value == '') search_value = search_box.value;
	
	if (search_box.value == search_value) {
		search_box.value = "";
	} else if (search_box.value == "") {
		search_box.value = search_value;
	}
}

function strstr (haystack, needle, bool) {
    // Finds first occurrence of a string within another  
    // 
    // version: 909.322
    // discuss at: http://phpjs.org/functions/strstr
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Onno Marsman
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: strstr('Kevin van Zonneveld', 'van');
    // *     returns 1: 'van Zonneveld'
    // *     example 2: strstr('Kevin van Zonneveld', 'van', true);
    // *     returns 2: 'Kevin '
    // *     example 3: strstr('name@example.com', '@');
    // *     returns 3: '@example.com'
    // *     example 4: strstr('name@example.com', '@', true);
    // *     returns 4: 'name'
    var pos = 0;
    
    haystack += '';
    pos = haystack.indexOf( needle );
    if (pos == -1) {
        return false;
    } else{
        if (bool){
            return haystack.substr( 0, pos );
        } else{
            return haystack.slice( pos );
        }
    }
}
 
this.screenshotPreview2 = function(){	
	/* CONFIG */
		
		xOffset = 30;
		yOffset = 0;
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	$(".img_pic_a").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='preview'><img src='"+ this.rel +"' width='325' height='325' />"+ c +"</p>");
		
		var v = viewport(),
			h = $("#preview");
		
		left = e.pageX + xOffset;
		top = e.pageY + yOffset;
		
		if (v.x + v.cx < left + 350) {
			left -= 370 + xOffset;
		}
		
		if (v.y + v.cy < top + 350) {
			top -= 370 + yOffset;
		}
		
		// console.log('view width:' + v.x);

		$("#preview")
			.css("top",top + "px")
			.css("left",left + "px")
			.fadeIn("fast");						 						
    },
	function(){
		this.title = this.t;	
		$("#preview").remove();
    });	
	$(".img_pic_a").mousemove(function(e){
		
		var v = viewport(),
			h = $("#preview");
		// check horizontal position
		// if (v.x + v.cx < h.offsetLeft + h.offsetWidth) {
		// 	left -= h.offsetWidth + 20 + settings(current).left;
		// 	console.log('left: ' + left);
		// }
		// // check vertical position
		// if (v.y + v.cy < h.offsetTop + h.offsetHeight) {
		// 	top -= h.offsetHeight + 20 + settings(current).top;
		// 	console.log('top:' + top);
		// }
		
		left = e.pageX + xOffset;
		top = e.pageY + yOffset;
		
		if (v.x + v.cx < left + 350) {
			left -= 370 + xOffset;
		}
		
		if (v.y + v.cy < top + 350) {
			top -= 370 + yOffset;
		}
		
		// console.log('view width:' + v.x);

		$("#preview")
			.css("top",top + "px")
			.css("left",left + "px");
		// .css("top",(e.pageY - xOffset) + "px")
		// .css("left",(e.pageX + yOffset) + "px");
		});			
};

this.screenshotPreview = function(){ 
    /* CONFIG */

        xOffset = 10;
        yOffset = 30;

        // these 2 variable determine popup's distance from the cursor
        // you might want to adjust to get the right result

    /* END CONFIG */
    $(".img_pic_a").hover(function(e){
        this.t = this.title;
        this.title = "";        
        var c = (this.t != "") ? "<br/>" + this.t : "";
        $("body").append("<p id='preview'><img src='"+ this.rel +"' width='325' height='325' />"+ c +"</p>");                                                                
        $("#preview")
                .css("top",(e.pageY - xOffset) + "px")
                .css("left",(e.pageX + yOffset) + "px")
                .fadeIn("fast");                                                
    },
    function(){
        this.title = this.t;    
        $("#preview").remove();
    }); 
    $(".img_pic_a").mousemove(function(e){
        $("#preview")
                .css("top",(e.pageY - xOffset) + "px")
                .css("left",(e.pageX + yOffset) + "px");
    });                 
};


function viewport() {
	return {
		x: $(window).scrollLeft(),
		y: $(window).scrollTop(),
		cx: $(window).width(),
		cy: $(window).height()
	};
}

var hblProto = document.location.protocol == 'https:' ? "https:" : "http:";
document.write(unescape("%3Cscript src='" + hblProto + "//static.olark.com/js/wc.js' type='text/javascript'%3E%3C/script%3E"));

// starting the script on page load
$(document).ready(function(){
	screenshotPreview();
	
	// comment this out to stop the test
	// hblRpcTrick = 1;
	// hbl_max_event = 4;
	// hbl_hostname = "rpc-dev.olark.com/rpc";
	// hbl_hostname_delimiter = "-";
	
	$("body").append("<a style=\"float: right;\" href=\"http://olark.com/#7735-249-10-9010\" id=\"hbl_code\">Olark Livehelp</a>");
	// Get web chat config, and set position
	var config = wc_config();
	config.vars.session_expire = 3600*1000*24;
	wc_init("7735-249-10-9010", config);
	search_box = document.getElementById("search_box");
	search_value = search_box.value;
});

function showcvv() {
	window.open ("http://graphicleftovers.com/cvv_what", "mywindow","menubar=0,resizable=1,width=570,height=640");
}